• gSpeak - Text To Speech in gmod
    86 replies, posted
  • Avatar of jA_cOp
  • [B]Description[/B] 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 [B]not[/B] broadcast voice output to clients. [code] gspeak.Say(string message [, ushort volume, long rate]) gspeak.IsSpeaking() gspeak.QueueSize() gspeak.Pause() gspeak.Resume() [/code] 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. [B]More on XML markup[/B] 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 [url=http://msdn.microsoft.com/en-us/library/ms717077(VS.85).aspx]here[/url]. [B]Example: Spoken chat[/B] 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] [B]Example: Console command[/B] [lua] concommand.Add("tts", function(ply, cmd, args) if #args == 0 then print("Usage: speak <message>") return end gspeak.Say(table.concat(args, " ")) end) [/lua] Usage (in console): [code]tts SamuraiMushroom is a faggot![/code] [B]Todo[/B] Add a mechanism for choosing/getting the default voice and language. [B]Temporary method of changing voice[/B] You have to select your system default voice in Control Panel->(Text To) Speech, the default voice is the one used by gspeak. [B]Download v1.6.2[/B] Put gm_speak.dll in your lua/includes/modules/ folder to use. [url=http://upl.luahelp.com/uploads/8FtcmT7w/gm_speak%201.6.2.zip]#luahelp download mirror[/url] [url=http://filesmelt.com/downloader/gm_speak_1.6_.2_.zip]filesmelt download mirror[/url] [B]Credits[/B] Foss - came up with the idea
  • Avatar of MajorVictory
  • Some SAPI Documentation for ya. Not sure if it works though... [url]http://www.w3.org/TR/speech-synthesis/#S3[/url]
  • Avatar of jA_cOp
  • New version put up, now lets you supply the rate and volume. [QUOTE=Kill coDer;14400328]If only you could stream this to clients...[/QUOTE] 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.
  • Avatar of Deco Da Man
  • [QUOTE=Foss;14401353]Idea stealer.[/QUOTE] 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!
  • Avatar of Nev
  • [QUOTE=jA_cOp;14400655]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.[/QUOTE] Doesn't source already have something like voip? You'd just need to bend the mic system to your way. Anyways.. Good work!
  • Avatar of maurits150
  • 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?
  • Avatar of CapsAdmin
  • [QUOTE=maurits150;14402029]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?[/QUOTE] Yeah it freezes gmod on my computer too.
  • Avatar of Deco Da Man
  • Threading would help with that problem, jA_cOp... I wonder if using the Lua Lanes module would work...
  • Avatar of ahref
  • [quote]WARNING: This file has been reported! It may be dangerous! Download at your own risk! If this is your file, don't waste your time editing the description to say the file is safe, if you do your file will be automatically deleted when it gets checked. [/quote] :O who did that. EDIT: SORRY FOR DOUBLE POST!
  • Avatar of YYZ
  • [QUOTE=ahref;14402368]:O who did that.[/QUOTE] Pretty sure files with DLLs in them are auto-reported or some shit.
  • Avatar of jA_cOp
  • 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.
  • Avatar of jA_cOp
  • 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: [url=http://www.garrysmod.org/downloads/?a=view&id=65675][img]http://www.garrysmod.org/img/?t=dll&id=65675[/img][/url] 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.
  • Avatar of jA_cOp
  • [QUOTE=CapsAdmin;14416366]Still freezes for me on gspeak.Say, but not when it loads.[/QUOTE] 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.
  • Avatar of maurits150
  • [QUOTE=jA_cOp;14416566]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.[/QUOTE] I just did this, and it still freezes.
  • Avatar of jA_cOp
  • [QUOTE=maurits150;14416812]I just did this, and it still freezes.[/QUOTE] 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.
  • Avatar of CapsAdmin
  • [QUOTE=jA_cOp;14417582]With the newest version? And using "require" or "gspeak.Say"? Thanks 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.[/QUOTE] I tried this, too. And yeah with the latest version.
  • Avatar of jA_cOp
  • [url=http://www.garrysmod.org/downloads/?a=view&id=65738][img]http://www.garrysmod.org/img/?t=dll&id=65738[/img][/url] New link up. It's a legit module and the source is included, why would anyone take it down? :S
  • Avatar of Kogitsune
  • [QUOTE=jA_cOp;14430528][url=http://www.garrysmod.org/downloads/?a=view&id=65738][img]http://www.garrysmod.org/img/?t=dll&id=65738[/img][/url] New link up. It's a legit module and the source is included, why would anyone take it down? :S[/QUOTE] Aren't DLLs auto-reported?
  • Avatar of mbainrot
  • Its brilliant, only prob is that its a halting call, the game locks up for 1/2 of a second while the call runs, have you tried calling it in its own "thread"?
  • Avatar of duck
  • [QUOTE=HubmaN;14430572]Anyone try this on Wine yet?[/QUOTE] As far as I'm aware, the WinE codebase doesn't have any binaries for TextToSpeech. Either try Crossover (I'll do this soon) or submit a Feature Request.
  • Avatar of FPtje
  • [QUOTE=Deco Da Man;14401841]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![/QUOTE] Haha I remember requesting this once too but that was years ago. Can't you send the module to the client and just send the text to a clientside lua file to let the client pay it? (I have no experience with modules so I don't know...)
  • Avatar of jA_cOp
  • [QUOTE=HubmaN;14430572]Anyone try this on Wine yet?[/QUOTE] Wine does not support any replacement for Windows' SAPI. [QUOTE=Kogitsune;14430844]Aren't DLLs auto-reported?[/QUOTE] Yeah, but it takes a moderator to look at it and take it down instead of mark it as checked and legit. [QUOTE=mbainrot;14430965]Its brilliant, only prob is that its a halting call, the game locks up for 1/2 of a second while the call runs, have you tried calling it in its own "thread"?[/QUOTE] It only freezes the first time it speaks. I am using a thread for the first time, but there's a way for Lua to grab that first call before the thread I am starting. I'll make a fix for it eventually. (by yielding the thread that calls the module's Init function, after launching the thread.) [QUOTE=FPtje;14430996]Can't you send the module to the client and just send the text to a clientside lua file to let the client pay it? (I have no experience with modules so I don't know...)[/QUOTE] You cannot send modules to the client. Well, you can, but not to the directory where you can load them in Lua. This is a good thing, else any server could do [B]anything[/B] they wanted to on their clients.
  • Avatar of mbainrot
  • [QUOTE=jA_cOp;14431178]Wine does not support any replacement for Windows' SAPI. Yeah, but it takes a moderator to look at it and take it down instead of mark it as checked and legit. It only freezes the first time it speaks. I am using a thread for the first time, but there's a way for Lua to grab that first call before the thread I am starting. I'll make a fix for it eventually. (by yielding the thread that calls the module's Init function, after launching the thread.) You cannot send modules to the client. Well, you can, but not to the directory where you can load them in Lua. This is a good thing, else any server could do [B]anything[/B] they wanted to on their clients.[/QUOTE] for me it locks up everytime, Damn I miss vista :( (right now i am on Win XP Pro SP3)