• Gmod TTS: 3D voice chatbox Text To Speech with accents!
    49 replies, posted
[QUOTE=WitheredPyre;47113553]So I did some experimentation with the above code and tried working it out, and found something out. One, you can't use ply for this, it has to be LocalPlayer(). Second, after I set it as LocalPlayer (which gets rid of the following error); [lua][ERROR] lua/autorun/client/gmodtts.lua:2: attempt to index global 'ply' (a nil value) 1. unknown - lua/autorun/client/gmodtts.lua:2[/lua] this error then appears, stating that Team is nil, even though Team is shared. [lua][ERROR] addons/gmodtts/lua/autorun/client/gmodtts.lua:8: attempt to call method 'Team' (a nil value) 1. unknown - addons/gmodtts/lua/autorun/client/gmodtts.lua:8[/lua] Thirdly, this doesn't work, even fi you load it as an addon or DarkRP module instead of putting it into lua/autorun/client. The problem is that Team is showing up as nil in this script even though it isn't (probably), as the above error states. Ignore the fact that the lines are different in the second error, I was testing putting the code into different positions. The error that occurred earlier was the exact same as that otherwise. This is my current code; [lua]if (not LocalPlayer():Team() == TEAM_ASTRO) then return end local accents = { "http://tts.peniscorp.com/speak.lua?" } local wait = false local channels = {} local function playvoice(ply,text,accent,speed) if wait then accent = "http://tts.peniscorp.com/speak.lua?" end sound.PlayURL(accent..text,"3d noplay",function(channel,errorid,errorname) if channel == nil || errorid != nil || errorname != nil then --peniscorp backup; google is upset if wait == false then wait = true timer.Simple(125,function() wait = false end) playvoice(ply,text,accent,speed) end return end channel:SetPos(ply:GetPos(),Vector(0,0,0)) channel:Set3DFadeDistance(300,9999999999) channel:SetPlaybackRate(math.Clamp(.5+speed,.5,2)) channel:Play() table.insert(channels,{channel,ply}) end) end hook.Add("Think","TTSThink",function() for k, v in pairs(channels) do if !v[1]:IsValid() then table.remove(channels,k) return end if v[2] == nil || v[1]:GetState() != GMOD_CHANNEL_PLAYING || v[1]:GetTime() >= v[1]:GetLength() then v[1]:Stop() table.remove(channels,k) return end v[1]:SetPos(v[2]:GetPos(),Vector(0,0,0)) end end) hook.Add("OnPlayerChat","TTSPlayerChat",function(ply,text,team,dead) --firstly, checking for popular gamemode limitations local dotts = true if engine.ActiveGamemode() == "terrortown" then if dead then dotts = false end if ply.IsSpec != nil && ply:IsSpec() then dotts = false end end if engine.ActiveGamemode() == "darkrp" then if text[1] == "/" then dotts = false end if text[1] == "@" then dotts = false end if ply:GetPos():Distance(LocalPlayer():GetPos()) > 500 then dotts = false end --250 = default chat range end if dotts then local speed,accent,nick = 1, accents[1], ply:Nick() local nlen = #nick local vowels, vow, notvow, vrat = {"a","e","i","o","u","y"}, 0, 0, 1 for i = 1, nlen do if table.HasValue(vowels,nick[i]) then vow = vow+1 else notvow = notvow+1 end end if vow == 0 then notvow = nlen end vrat = vow/notvow accent = accents[math.Clamp(vow,1,#accents)] speed = vrat playvoice(ply,text,accent,speed) end end)[/lua][/QUOTE] no, you're doing it wrong. the ply if statement is supposed to be in the playvoice function. what you've done is basically disable the entire script unless their team is TEAM_ASTRO on initialization of the script. [editline]10th February 2015[/editline] [QUOTE=AnonymaPizza;47114469]So I found out that despite this code being clientside, if someone hosts a listenserver with this code, everyone can hear it. It's great, I wonder if the same applies to dedicated servers.[/QUOTE] the reason everyone can hear it is because the person with the addon is HOSTING the server. so no, you cannot join some random server and use this and expect everyone to hear it. [editline]10th February 2015[/editline] that is unless you install it on the server
*snip*
[QUOTE=WitheredPyre;47114483][lua]local function playvoice(ply,text,accent,speed) if (not LocalPlayer():Team() == TEAM_ASTRO) then return end if wait then accent = "http://tts.peniscorp.com/speak.lua?" end sound.PlayURL(accent..text,"3d noplay",function(channel,errorid,errorname) if channel == nil || errorid != nil || errorname != nil then --peniscorp backup; google is upset if wait == false then wait = true timer.Simple(125,function() wait = false end) playvoice(ply,text,accent,speed) end return end channel:SetPos(ply:GetPos(),Vector(0,0,0)) channel:Set3DFadeDistance(300,9999999999) channel:SetPlaybackRate(math.Clamp(.5+speed,.5,2)) channel:Play() table.insert(channels,{channel,ply}) end) end[/lua] So is this correct, then? No, it isn't, apparently; [lua][ERROR] addons/gmodtts/lua/autorun/client/gmodtts.lua:1: attempt to call method 'Team' (a nil value) 1. unknown - addons/gmodtts/lua/autorun/client/gmodtts.lua:1 [/lua] Can we not rate me dumb for this? I know that I'm doing it wrong, evidently, but that's why I'm asking here, to get help with it.[/QUOTE] [B][I][U]use the original code snippet you were provided.[/U][/I][/B] [QUOTE=Author.;47113467][lua]if (not ply:Team() == TEAM_DERP) then return end[/lua][/QUOTE]
[QUOTE=TylerB;47114471] the reason everyone can hear it is because the person with the addon is HOSTING the server. so no, you cannot join some random server and use this and expect everyone to hear it. [editline]10th February 2015[/editline] that is unless you install it on the server[/QUOTE] Right, I just wanted to know if the same applied for the lua code being inserted into a dedicated server, which I imagine is a pretty good chance. Additionally, I had wanted to remove the 3D falloff so that anyone can hear each other serverwide, but changing this snip of code caused nothing: [CODE] channel:Set3DFadeDistance(300,9999999999)[/CODE] My first try was to change the fadedistance to -1 as with [CODE] channel:Set3DFadeDistance(-1,9999999999)[/CODE] But when that failed, I had just removed that line of code entirely. To no avail, it still has the same distance limit. I would also love to change the volume to be a bit higher, if possible.
just change the sound.PlayURL part of the code, remove the "3d" and just leave "noplay"
[lua]local accents = { "http://tts.peniscorp.com/speak.lua?" } local wait = false local channels = {} local function playvoice(ply,text,accent,speed) if (not ply:Team() == TEAM_ASTRO) then return end if wait then accent = "http://tts.peniscorp.com/speak.lua?" end sound.PlayURL(accent..text,"3d noplay",function(channel,errorid,errorname) if channel == nil || errorid != nil || errorname != nil then --peniscorp backup; google is upset if wait == false then wait = true timer.Simple(125,function() wait = false end) playvoice(ply,text,accent,speed) end return end channel:SetPos(ply:GetPos(),Vector(0,0,0)) channel:Set3DFadeDistance(300,9999999999) channel:SetPlaybackRate(math.Clamp(.5+speed,.5,2)) channel:Play() table.insert(channels,{channel,ply}) end) end hook.Add("Think","TTSThink",function() for k, v in pairs(channels) do if !v[1]:IsValid() then table.remove(channels,k) return end if v[2] == nil || v[1]:GetState() != GMOD_CHANNEL_PLAYING || v[1]:GetTime() >= v[1]:GetLength() then v[1]:Stop() table.remove(channels,k) return end v[1]:SetPos(v[2]:GetPos(),Vector(0,0,0)) end end) hook.Add("OnPlayerChat","TTSPlayerChat",function(ply,text,team,dead) --firstly, checking for popular gamemode limitations local dotts = true if engine.ActiveGamemode() == "terrortown" then if dead then dotts = false end if ply.IsSpec != nil && ply:IsSpec() then dotts = false end end if engine.ActiveGamemode() == "darkrp" then if text[1] == "/" then dotts = false end if ply:GetPos():Distance(LocalPlayer():GetPos()) > 500 then dotts = false end --250 = default chat range end if dotts then local speed,accent,nick = 1, accents[1], ply:Nick() local nlen = #nick local vowels, vow, notvow, vrat = {"a","e","i","o","u","y"}, 0, 0, 1 for i = 1, nlen do if table.HasValue(vowels,nick[i]) then vow = vow+1 else notvow = notvow+1 end end if vow == 0 then notvow = nlen end vrat = vow/notvow accent = accents[math.Clamp(vow,1,#accents)] speed = vrat playvoice(ply,text,accent,speed) end end)[/lua] I put the code right underneath the playvoice function. The code itself works still, but the restriction doesn't; I can still use the TTS on all teams. Sometimes, it doesn't even work, but this might be latency issues?
[QUOTE=TylerB;47114567]just change the sound.PlayURL part of the code, remove the "3d" and just leave "noplay"[/QUOTE] Thanks, that seemed to have done the trick! Shame that peniscorp's audio doesn't work half the time for me
It seems like this has broken as of the March 18th update for the TTS API. Can we get a fix? You can actually hear it saying what you're typing for a split second before it cuts out.
Sounds like a problem on their end. Ask GranPC.
How would I edit the code so only a certain rank could use it? I tried: [lua] local dotts = true if engine.ActiveGamemode() == "terrortown" then if ply:IsUserGroup("owner") then dotts = true else dotts = false end if dead then dotts = false end if ply.IsSpec != nil && ply:IsSpec() then dotts = false end end[/lua] and got: [url]http://prntscr.com/6jjitz[/url]
[code] if engine.ActiveGamemode() == "darkrp" then if ply:Team() ~= TEAM_NAME then dotts = false end[/code]
It'd be so sick of someone made it a legit addon with something like !tts insertuselessmaymay available only for set ULX ranks. I'd do it but I know jack shit about lua :/
[QUOTE=rikyy;47375798]It'd be so sick of someone made it a legit addon with something like !tts insertuselessmaymay available only for set ULX ranks. I'd do it but I know jack shit about lua :/[/QUOTE] But why ULX? Why not just standalone like this already offers.
-snip-
It'd be nice if we could get this as a library
-snip-
-snip-
I do realize this thread is pretty old by now, but does anyone know what ever happened to all the TTS sites? Google now requires you to pay + verification PenisCorp TTS seems to have been shutdown tts-api.com seemed to have shutdown Are there any working ones still out there? :@
Are there any working TTS addons as of now? From the code, it used peniscorp lua, does anyone have a backup? I'd like to make my server more accessible and users oftenly ask of something like this. May be I could rewrite it.
dude fix please speech (your api deleted(removed)) fix script, thanks :smug:
Sorry, you need to Log In to post a reply to this thread.