2022-05-02 17:31:40 +00:00
|
|
|
--@name GimpyTTS
|
2022-06-22 00:56:01 +00:00
|
|
|
--@author Mavain, Minori, Henke, et al.
|
2022-05-02 17:31:40 +00:00
|
|
|
--@client
|
|
|
|
|
2022-06-02 14:33:54 +00:00
|
|
|
local VALID_LANGS = {"en-gb", "en-ca", "en-us", "en-au", "ja", "ph", "so"}
|
2022-06-22 01:55:12 +00:00
|
|
|
local errorLookup = {[2] = "Invalid language"}
|
2022-06-02 14:33:54 +00:00
|
|
|
|
2022-05-17 15:33:32 +00:00
|
|
|
local lang = "en-gb"
|
2022-06-22 01:55:12 +00:00
|
|
|
local curLang = lang
|
2022-05-02 17:31:40 +00:00
|
|
|
local soundref
|
|
|
|
|
2022-06-22 01:37:14 +00:00
|
|
|
-- Check if client has permission
|
|
|
|
if not hasPermission("bass.loadURL", "https://translate.google.com/translate_tts") then return end
|
|
|
|
|
2022-06-02 14:33:54 +00:00
|
|
|
-- A local function to check if this exists on our valid langs
|
|
|
|
-- if it doesn't, we throw error
|
|
|
|
local function has_value (tab, val)
|
|
|
|
for index, value in ipairs(tab) do
|
|
|
|
if value == val then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2022-06-22 01:55:12 +00:00
|
|
|
local function RequestTTS(txt, l, callback)
|
|
|
|
bass.loadURL("https://translate.google.com/translate_tts?ie=UTF-8&q=" .. txt .. "&tl=" .. curLang .. "&client=tw-ob", "3d", callback)
|
2022-06-22 01:37:14 +00:00
|
|
|
end
|
|
|
|
|
2022-06-22 01:55:12 +00:00
|
|
|
local function DoTTS(sound)
|
|
|
|
-- we dispose the current reference, then we create a new one
|
|
|
|
if soundref then soundref:stop() end
|
|
|
|
soundref = sound
|
|
|
|
|
|
|
|
--local soundLength = sound:getLength()
|
|
|
|
hook.add("think", "soundFollow", function()
|
|
|
|
if sound:isValid() then sound:setPos(owner():getPos()) else
|
|
|
|
hook.remove("think", "soundFollow")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
sound:play()
|
2022-06-22 01:37:14 +00:00
|
|
|
end
|
|
|
|
|
2022-06-22 00:56:01 +00:00
|
|
|
hook.add("playerchat", "fucke2", function(ply, txt)
|
2022-05-02 17:31:40 +00:00
|
|
|
if ply ~= owner() then return end
|
|
|
|
|
2022-06-22 00:56:01 +00:00
|
|
|
if string.sub(txt, 1, 1) == ":" then
|
|
|
|
local l = string.gsub(txt, ":", "")
|
|
|
|
if #l > 1 then
|
|
|
|
local lastLang = l
|
|
|
|
|
2022-06-22 01:00:03 +00:00
|
|
|
if has_value(VALID_LANGS, l) then
|
2022-06-22 00:56:01 +00:00
|
|
|
lang = l
|
|
|
|
else
|
|
|
|
print("Invalid parameter, check source for valid languages.")
|
2022-06-22 00:57:48 +00:00
|
|
|
-- Do not error, just reassign back the last language selection
|
2022-06-22 00:56:01 +00:00
|
|
|
lang = lastLang
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-06-22 01:37:14 +00:00
|
|
|
|
2022-05-15 01:56:25 +00:00
|
|
|
if string.sub(txt, 1, 1) ~= ";" then return end
|
2022-06-09 15:56:07 +00:00
|
|
|
|
2022-06-22 00:56:01 +00:00
|
|
|
txt = string.sub(txt,2)
|
|
|
|
if #txt < 1 then return end
|
|
|
|
|
|
|
|
txt = http.urlEncode(txt)
|
2022-05-15 01:56:25 +00:00
|
|
|
|
2022-06-22 01:55:12 +00:00
|
|
|
RequestTTS(txt, curLang, function(sound, err, name)
|
2022-06-22 00:56:01 +00:00
|
|
|
|
2022-06-22 01:37:14 +00:00
|
|
|
if not sound then
|
2022-06-22 01:55:12 +00:00
|
|
|
print("error: " .. errorLookup[err])
|
|
|
|
|
|
|
|
if err == 2 then
|
|
|
|
lang = curLang
|
|
|
|
|
|
|
|
RequestTTS(txt, curLang, function(s, e, n)
|
|
|
|
if not sound then return end
|
|
|
|
|
|
|
|
DoTTS(sound)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2022-06-22 00:56:01 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-06-22 01:55:12 +00:00
|
|
|
DoTTS(sound)
|
2022-06-22 00:56:01 +00:00
|
|
|
end)
|
|
|
|
end)
|