tts wieder mehrsprachig

This commit is contained in:
Akamaru 2016-04-07 20:21:48 +02:00
parent 2c8c66cce3
commit 0dbf087456
1 changed files with 22 additions and 6 deletions

View File

@ -1,7 +1,21 @@
local function run(msg, matches)
local receiver = get_receiver(msg)
local text = matches[1]
if matches[2] == nil then
text = matches[1]
lang = 'de'
else
text = matches[2]
lang = matches[1]
end
local b = 1
local text = string.gsub(text, "%+", "plus")
while b ~= 0 do
text,b = text:gsub('^+','+')
text = text:trim()
end
local text = string.gsub(text, "%s+", "+")
local text = string.gsub(text, "ä", "ae")
local text = string.gsub(text, "Ä", "Ae")
local text = string.gsub(text, "ö", "oe")
@ -10,11 +24,11 @@ local function run(msg, matches)
local text = string.gsub(text, "Ü", "Ue")
local text = string.gsub(text, "ß", "ss")
local text = string.gsub(text, "%&", "und")
if string.len(text) > 160 then return 'Text zu lang!' end
local text = string.gsub(text, " ", "+")
local url = "http://tts.baidu.com/text2audio?lan=en&ie=UTF-8&text="..text
local url = 'http://tts.baidu.com/text2audio?lan='..lang..'&ie=UTF-8&text='..text
local file = download_to_file(url, text..'.mp3')
if file == nil then
if not file then
return "Ein Fehler ist aufgetreten, besuche die URL eventuell direkt?\n"..url
end
local cb_extra = {file_path=file}
@ -24,10 +38,12 @@ end
return {
description = "Text-To-Speech",
usage = {
"/tts [Text]: Sendet Sprachnachricht mit dem Text"
"/tts [Text]: Sendet Sprachnachricht mit dem Text",
"/tts(Sprache) [Text]: Sendet Sprachnachricht in der Sprache mit dem Text"
},
patterns = {
"^/tts (.+)$"
"^/tts (.+)$",
"^/tts(%w+) (.+)$"
},
run = run
}