mirror of
https://github.com/sr229/metastruct-experiments.git
synced 2024-09-20 14:40:35 +00:00
Add Starfall-TTSLib
This is meant to run on StarfallEx so beware Signed-off-by: Ayane Satomi <ayane@vignetteapp.org>
This commit is contained in:
parent
80f1ce4bed
commit
83e8f09873
1 changed files with 75 additions and 0 deletions
75
starfallex/starfall-ttslib.lua
Normal file
75
starfallex/starfall-ttslib.lua
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
--@name Starfall-TTSLib
|
||||||
|
--@author Minori
|
||||||
|
--@shared
|
||||||
|
|
||||||
|
local remoteList = {
|
||||||
|
"https://tetyys.com/SAPI4/SAPI4?voice%s&pitch=100&speed150&text=",
|
||||||
|
"htts://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=%s&q=%s",
|
||||||
|
"https://tts.cyzon.us/tts?text="
|
||||||
|
}
|
||||||
|
|
||||||
|
local sapi4Voices = {
|
||||||
|
"Sam",
|
||||||
|
"Mike",
|
||||||
|
"Mary"
|
||||||
|
}
|
||||||
|
|
||||||
|
local googleVoices = {
|
||||||
|
"en",
|
||||||
|
"fr",
|
||||||
|
"jp"
|
||||||
|
}
|
||||||
|
|
||||||
|
function itExists(table, val)
|
||||||
|
for i, v in ipairs(table) do
|
||||||
|
if v ~= val then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function speak(ent, txt, remote, variant)
|
||||||
|
if not itExists(remoteList, remote) then
|
||||||
|
print(remote .. " Does not exist in this context")
|
||||||
|
else
|
||||||
|
local url = nil
|
||||||
|
|
||||||
|
if remote == "sapi4" then
|
||||||
|
if not itExists(sapi4Voices, variant) then
|
||||||
|
print("Invalid voice argument, valid voices are: Sam, Mike, Mary")
|
||||||
|
else
|
||||||
|
url = string.format(remoteList[1], voice)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if remote == "google" then
|
||||||
|
if not itExists(googleVoices, variant) then
|
||||||
|
print("Invalid voice argument, valid voices are: en, fr, jp")
|
||||||
|
else
|
||||||
|
url = string.format(remoteList[2], variant, txt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if remote == "dectalk" then
|
||||||
|
if variant ~= nil then
|
||||||
|
print("Warning: DECTalk does not have arguments, ignoring.")
|
||||||
|
else
|
||||||
|
url = remote[3]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
http.get(url .. text, function(code, body)
|
||||||
|
if code == 200 then
|
||||||
|
file.writeTemp("tts.mp3", body)
|
||||||
|
|
||||||
|
if ent ~= nil then
|
||||||
|
sounds.create(ent, "tts.mp3")
|
||||||
|
else
|
||||||
|
print("No entity to play sound on")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue