gSpeak - Text To Speech in gmod

Description
gSpeak is a module for gmod that lets you use Microsoft Speech from Lua. You can use it both on the server and the client, but it makes more sense on the client. If you use it on the server, gSpeak will not broadcast voice output to clients.



gspeak.Say(string message [, ushort volume, long rate])
gspeak.IsSpeaking()
gspeak.QueueSize()
gspeak.Pause()
gspeak.Resume()


gspeak.Say makes your system default voice (XP: Sam, Vista: Anna) speak the provided message, optionally also at the provided volume and rate of speech. The volume is a value between 0 and 100, where 100 is the default. The rate is a value between -10 and 10, where 0 is typically the default. You can also use the SAPI’s XML markup within the message to mutate the pitch, volume and rate of speech.

gspeak.IsSpeaking returns a boolean value whether or not gspeak is currently saying anything.

gspeak.QueueSize returns the amount of messages currently waiting to be spoken, including the one currently being spoken.

gspeak.Pause pauses the voice temporarily before the next word. IsSpeaking returns false while the voice is paused; even if the voice is currently finishing up on a word before pausing.

gspeak.Resume resumes a paused voice. You can use Pause and Resume even if the voice is already paused or is already speaking; they’ll just return immediately, so there’s no need to use IsSpeaking/QueueSize to check if pausing/resuming is viable.

More on XML markup
The XML markup can be used to modify the pronounciation of entire text or just portions of it. You can change attributes such as pitch, volume and rate using the embedded XML. You can also insert pockets of silence, or tell the voice how to pronounce something.

More advanced features include making the current voice be chosen based on gender, age and language!

I have not tested all of these features, but there’s a detailed tutorial on the XML markup here.

Example: Spoken chat
Clientside script for speaking out chat (and notifications, leave messages):
[lua]
require(“speak”)

local function speak(index, nick, msg, msgtype)
gspeak.Say(msg)
end
hook.Add(“ChatText”, “gspeak_saychat”, speak)
[/lua]

Example: Console command
[lua]
concommand.Add(“tts”, function(ply, cmd, args)
if #args == 0 then print("Usage: speak ") return end
gspeak.Say(table.concat(args, " "))
end)
[/lua]
Usage (in console):


tts SamuraiMushroom is a faggot!

Todo
Add a mechanism for choosing/getting the default voice and language.

Temporary method of changing voice
You have to select your system default voice in Control Panel->(Text To) Speech, the default voice is the one used by gspeak.

Download v1.6.2
Put gm_speak.dll in your lua/includes/modules/ folder to use.
#luahelp download mirror
filesmelt download mirror

Credits
Foss - came up with the idea

Some SAPI Documentation for ya. Not sure if it works though…

If only you could stream this to clients…

New version put up, now lets you supply the rate and volume.

I can only see this possible by sending the sound data to the client, generate a sound file in the data folder then play that file. This is extremely slow compared to regular techniques like VOIP.

Idea stealer.

I’m pretty sure that many people had thought of the idea much earlier than you first even considered it.

And having an idea doesn’t give you credit to it. You actually need to create it.

…unless you take out a patent… but I doubt you could do that in this situation.

Anyway: Awesomely Awesome module!

Doesn’t source already have something like voip? You’d just need to bend the mic system to your way.

Anyways… Good work!

Very nice module. I only have a problem.
When I use it, the game freezes until the voice has been finished saying its line.
Am I the only person with this problem?

Yeah it freezes gmod on my computer too.

Threading would help with that problem, jA_cOp…

I wonder if using the Lua Lanes module would work…

anyone not have the freezing problem?

:open_mouth: who did that.

EDIT: SORRY FOR DOUBLE POST!

Pretty sure files with DLLs in them are auto-reported or some shit.

i figured since calling the speak function (which is done on module initialization) doesn’t block, it would have no effect on the loading. So I assumed the freeze was because of the other loading stuff. I’ll try taking that out and see what happens.

Alright when I take that out, the freeze happens the first time gspeak.Say is called instead.

I could move the initialization into another thread though. I’ll do that now.

edit:

Here we go:
http://www.garrysmod.org/img/?t=dll&id=65675

I could thread the whole initialization, but then the first script to require the module would get nil errors for global “gspeak”, so I think it’s best to leave the actual initialization blocking. The “gSpeak loaded” line has been moved into a seperate thread though, and I felt that it helped loading a little bit. Try it and see how it acts for you.

Still freezes for me on gspeak.Say, but not when it loads.

Weird. Perhaps ‘require’ manages to return and call gspeak.Say in your script before my thread gets any time. Could you try doing require and gspeak.Say in seperate lua_run_cl commands? See if it freezes anywhere, and where.

I just did this, and it still freezes.

With the newest version? And using “require” or “gspeak.Say”?

Thanks for any help. I’m currently at a laptop where I get like 3 FPS in gmod under most conditions, so it’s fairly difficult to get any decisive results from testing.

I tried this, too.

And yeah with the latest version.