Speaking warnings

Posted by Nick Gammon on Sat 27 May 2006 10:43 PM — 11 posts, 51,732 views.

Australia Forum Administrator #0
Some ideas presented in another thread show how to speak things using the SAPI COM object:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6586

As that is a VBscript thread, in the Lua section I will show how you could make a trigger that speaks a warning when your health is low:


<triggers>
  <trigger
   enabled="y"
   match="^\&lt;(\d+)\/(\d+)hp (\d+)\/(\d+)m (\d+)\/(\d+)mv (\d+)\/(\d+)xp\&gt;"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>if not talk then
  assert (loadlib ("luacom.dll","luaopen_luacom")) ()
  talk = assert (luacom.CreateObject ("SAPI.SpVoice"), "cannot open SAPI")
end -- no talk yet

if %1 &lt; 100 and oldhealth ~= %1 then
  talk:Speak ("Health is down to %1!", 1)
  oldhealth = %1  -- remember health level
end -- low health</send>
  </trigger>
</triggers>



For this to work you need luacom.dll in the same directory as MUSHclient.exe, which I found at:


http://luaforge.net/frs/download.php/922/luacom-1.3-luabinaries-bin.zip


This uses a test on the "talk" variable to save re-instantiating the COM object every time the trigger fires. It also does asynchronous speaking (thanks, Ked!) so the client does not pause while it speaks.

It also remembers the last health level to save repeating the same value.
#1
For some reason, when I try to use this it DOES pause the client. Triggers and stuff may or may not still be processed but I can't see it, because nothing is updated on the GUI while it speaks.

Im not sure if that's full pausing of the client or not but it's still annoying. Wish it didn't do that. :(
Australia Forum Administrator #2
Seems to be working OK for me, the GUI keeps updating.
Australia Forum Administrator #3
I'm not sure if this is the right file, but I have:


C:\Program Files\Common Files\Microsoft Shared\Speech\sapi.dll


Its version is 5.1.4111.0.
#4
Sorry. Im an idiot and I didn't read the thread you linked.

I wasn't passing 1 to the speak object. *sigh*
Australia #5
Nick,

Using 3.80, I get the error below for this trigger;

[string "Trigger: "]:1: The specified procedure could not be found.
stack traceback:
[C]: in function 'assert'
[string "Trigger: "]:1: in main chunk

I've changed loadlib to package.loadlib, and have luacom.dll 5.1 in the mushclient directory.

Any clues you could offer to point me to the next step?

Thanks.
Australia Forum Administrator #6
After a bit of research I found that the entry point had been renamed. The line that loads the SAPI interface now needs to read:


assert (package.loadlib ("luacom.dll","luacom_open")) ()

Australia #7
that change worked for me, thanks Nick. I'd been using some *.wav files to alert me to special events, but I really don't like the soundof my voice, so sam is much better.

Thanks!
#8
I thought I'd try this, but every time this line is executed:
 assert (package.loadlib ("luacom.dll","luacom_open")) ()

MUSHClient 3.84 crashes with one of Windows' "Do you want to send an error report?" messages. Flicking through the report dump, Lua 5.0.2 (which is odd - I thought MUSHClient was using 5.1 - and removing the lua50.dll from the MUSHClient directory makes the line throw up an error "The specified module could not be found.") seems to be giving an error like:
control structure too long.
function or expression too complex..
constant table overflow.
code size overflow.
value for 'lua_getinfo' is not a function..

Followed by a whole bunch of other errors, and finally:
loadlib.init....
system error %d



Any insight?
Australia Forum Administrator #9
It sounds very much like you are using a version of luacom.dll which is designed for Lua 5.0, hence the fact that it is loading the lua50.dll file.

See:

http://www.gammon.com.au/forum/?id=7341

In there are links for downloads for luacom.dll which is designed for Lua 5.1.
#10
Ah, thanks. I didn't spot that when I was flicking over the warning.