Skip to content

fiendish/MS_Speech_API_Lua

Repository files navigation

Lua COM interface for Microsoft Speech API

Easy text-to-speech in Lua with MS SAPI ( https://en.wikipedia.org/wiki/Microsoft_Speech_API ).

Dependencies

LuaCOM ( https://github.com/davidm/luacom or maybe better https://github.com/moteus/luacom )

Note for use on non-Microsoft systems with Wine

SAPI speech functionality depends on the Microsoft Speech API, which is not included by default in Wine, and SpeechSDK51.exe must be separately installed. You can install it with winetricks speechsdk or download it from https://download.microsoft.com/download/B/4/3/B4314928-7B71-4336-9DE7-6FA4CF00B7B3/SpeechSDK51.exe

API

Function Arguments Returns Description
say string message Speak the given string.
pause Pause speaking.
resume Resume speaking.
skip_sentence Stop speaking the current line and move to the next line in the SAPI buffer.
skip_all Stop speaking and clear the SAPI buffer.
set_voice_by_number int SAPI_index, [bool quietly] int SAPI_index, string SAPI_ID Choose the SAPI voice indexed from 1 to n
set_voice_by_id string SAPI_ID, [bool quietly] int SAPI_index, string SAPI_ID Choose the SAPI voice by its ID.
set_rate int rate, [bool quietly] int rate Set the speech rate.
slower [bool quietly] int rate Increment the speech rate.
faster [bool quietly] int rate Decrement the speech rate.
set_filtering_level int level, [bool quietly] int level Set the symbol filtering level, 1 being least and 3 being most filtering.
set_volume int volume, [bool quietly] int volume Set the speech volume.
quieter [bool quietly] int volume Decrement the speech volume.
louder [bool quietly] int volume Increment the speech volume.
get_voice_id string SAPI_ID Return the SAPI voice ID string.
get_rate int rate Return the speech rate number.
get_filtering_level int level Return the filtering level number.
get_volume int volume Return the speech volume number.
say_current_voice Speaks the current voice index and ID.
say_current_rate Speaks the current speech rate.
say_current_filtering_level Speaks the current symbol filtering level and description.
say_current_volume Speaks the current speech volume.
list_voices Speaks all of the available voices, index and ID.
list_filtering_levels Speaks all of the filtering levels, index and description.
mute [bool quietly] Disables speech.
unmute [bool quietly] Re-enables speech.
speech_demo Speaks a set of demonstration sentences.
print_spoken Print spoken lines to the screen to aid debugging.
Variables Description
replacements Table of tables in the form {string pattern, string replacement} for filtering level 3 via string.gsub.

Usage Example

sapi_interface = require "sapi_interface"

if sapi_interface == -1 then
  print([[
  Could not open SAPI.
  Note for non-Microsoft operating systems...
  SAPI speech functionality depends on the Microsoft Speech API.
  This is not included by default in Wine, and SpeechSDK51.exe must be separately installed.
  You can download it from
  https://download.microsoft.com/download/B/4/3/B4314928-7B71-4336-9DE7-6FA4CF00B7B3/SpeechSDK51.exe
  ]])
  return
end

if sapi_interface == -2 then
  print("No SAPI voices found.")
  return
end

-- add a new filter
table.insert(sapi_interface.replacements, {"%f[%a][gG]clan", " G clan"})

sapi_interface.say("SAPI interface is ready")
sapi_interface.speech_demo()

About

Lua COM interface for Microsoft Speech API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages