[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Lua SAPI TTS module
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Lua SAPI TTS module

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Sat 24 Dec 2016 03:24 PM (UTC)

Amended on Sat 24 Dec 2016 03:25 PM (UTC) by Fiendish

Message
I took all the expansion work I did on the SAPI text to speech plugin, and spun it out into a Lua module so that it can be used anywhere.

https://github.com/fiendish/MS_Speech_API_Lua

A now modular form of the same plugin is:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="Text_To_Speech"
   author="Avi Kelman (Fiendish)"
   id="463242566069ebfd1b379ec1"
   language="Lua"
   purpose="Speaks incoming text using SAPI."
   date_written="2010-09-01"
   requires="4.60"
   version="2.0"
   save_state="y"
   >
   
<description trim="y">
Text To Speech Plug-in Commands:

 sapi on                 : turn on automatic speaking of MUD output.
 sapi off                : turn off automatic speaking of MUD output.
 sapi skip               : skips one sentence in output stream.
 sapi clear              : clear the speech output queue.
 sapi faster             : speeds speech up.
 sapi slower             : slows speech down.
 sapi rate [number]      : check or set speech rate to [number].
 sapi list voices        : list the available TTS voices.
 sapi voice [number]     : check or set to the given TTS voice number.
 sapi test               : speak a test phrase.
 sapi filtering [number] : check or set punctuation filtering level to [number].
 sapi say [text]         : speak the given text.

Scripts can also speak stuff by doing:

 CallPlugin ("463242566069ebfd1b379ec1", "say", "What to say")
</description>
</plugin>

<aliases>
  <alias
   match="sapi on"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.unmute()
   </send>
  </alias>

  <alias
   match="sapi off"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.mute()
   </send>
  </alias>
  
  <alias
   match="sapi faster"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   SetVariable("engine_Rate", tostring(sapi_interface.faster()))
   </send>
  </alias>
  
  <alias
   match="sapi slower"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   
   SetVariable("engine_Rate", tostring(sapi_interface.slower()))
   </send>
  </alias>
    
  <alias
   match="sapi voice*"
   regexp="n"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   local arg = Trim("%1")
   if arg == "" then
      sapi_interface.say_current_voice()
   else
      local index,id = sapi_interface.set_voice_by_number(arg)
      SetVariable("engine_Voice_ID", tostring(id))
   end
   </send>
  </alias>
  
  <alias
   match="sapi list voices"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.list_voices()
   </send>
  </alias>
    
  <alias
   match="sapi test"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.speech_demo()
   </send>
  </alias>
  
  <alias
   match="sapi rate*"
   enabled="n"
   regexp="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   local arg = Trim("%1")
   if arg == "" then
      sapi_interface.say_current_rate()
   else
      SetVariable("engine_Rate", tostring(sapi_interface.set_rate(arg)))
   end
   </send>
  </alias>
  
  <alias
   match="sapi skip"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.skip_sentence()
   </send>
  </alias>

  <alias
   match="sapi clear"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.skip_all()
   </send>
  </alias>
  
  <alias
   match="sapi say *"
   regexp="n"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.say("%1")
   </send>
  </alias>
    
  <alias
   match="sapi help"
   regexp="n"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.say("This help is being spoken but not printed to the screen. To print it to the screen, use: sapi help printed.")
   sapi_interface.say(GetPluginInfo(GetPluginID(), 3), true)
   </send>
  </alias>

  <alias
   match="sapi help printed"
   regexp="n"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="99"
   group="speech"
   send_to="12"
  ><send>
   print(GetPluginInfo(GetPluginID(), 3), true)
   </send>
  </alias>

  <alias
   match="sapi debug"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   sapi_interface.print_spoken()
   </send>
  </alias>
  
  <alias
   match="sapi filtering*"
   regexp="n"
   enabled="n"
   omit_from_log="y"
   omit_from_output="y"
   sequence="100"
   group="speech"
   send_to="12"
  ><send>
   local arg = Trim("%1")
   if arg == "" then
      sapi_interface.say_current_filtering_level()
   else
      SetVariable("filtering_level", tostring(sapi_interface.set_filtering_level(arg)))
   end
   </send>
  </alias>
</aliases>

<triggers>
</triggers>

<script>
<![CDATA[

function OnPluginInstall ()
   sapi_interface = require "sapi_interface"
   
   if sapi_interface == -1 then
      print([[
      Could not open SAPI.
      Note for Linux and Mac OS users...
      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 http://download.microsoft.com/download/B/4/3/B4314928-7B71-4336-9DE7-6FA4CF00B7B3/SpeechSDK51.exe
      ]])
      sapi_interface = nil
      return
   end

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

   local new_filter = tonumber(GetVariable("filtering_level"))
   if new_filter then
      sapi_interface.set_filtering_level(new_filter, true)
   end
   
   local new_rate = tonumber(GetVariable("engine_Rate"))
   if new_rate then
      sapi_interface.set_rate(new_rate, true)
   end
   
   local new_voice = GetVariable("engine_Voice_ID")
   if new_voice then
      sapi_interface.set_voice_by_id(new_voice, true)
   end

   EnableGroup("speech", true)
   
   sapi_interface.say("SAPI Plugin installed and is ready")
   sapi_interface.speech_demo()
end

local installed = false
function OnPluginListChanged()
   if not installed then
      installed = true  -- to prevent reading MUSHclient's Added/Reinstalled plugin messages
   end
end

-- here to draw the screen
function OnPluginScreendraw (t, log, line)
   if installed and sapi_interface and (t == 0 or t == 1) then
      sapi_interface.say(line)
   end
end

function OnPluginTabComplete (line)
   if sapi_interface then
      sapi_interface.say(line)
   end
end

]]>
</script>
</muclient>

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 27 Dec 2016 04:53 AM (UTC)
Message
Very good, thank you.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


1,376 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]