This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/tts.lua

49 lines
1.4 KiB
Lua
Raw Normal View History

2015-06-06 22:16:11 +02:00
-- TTS plugin in lua
local function run(msg, matches)
local receiver = get_receiver(msg)
if matches[2] == nil then
text = matches[1]
lang = 'de'
else
text = matches[2]
lang = matches[1]
end
local b = 1
2015-09-07 18:12:27 +02:00
2015-06-10 14:29:22 +02:00
local text = string.gsub(text, "%+", "plus")
2015-06-06 22:16:11 +02:00
while b ~= 0 do
text,b = text:gsub('^+','+')
text = text:trim()
end
2015-09-07 18:12:27 +02:00
2015-06-06 22:16:11 +02:00
local text = string.gsub(text, "%s+", "+")
2015-09-07 18:12:27 +02:00
-- because everyone loves german umlauts, right? :3
2015-06-06 22:16:11 +02:00
local text = string.gsub(text, "ä", "ae")
local text = string.gsub(text, "Ä", "Ae")
local text = string.gsub(text, "ö", "oe")
local text = string.gsub(text, "Ö", "Oe")
local text = string.gsub(text, "ü", "ue")
local text = string.gsub(text, "Ü", "Ue")
local text = string.gsub(text, "ß", "ss")
2015-09-07 18:12:27 +02:00
local text = string.gsub(text, "%&", "und")
local url = "http://translate.google.com/translate_tts?tl="..lang.."&q="..text.."&ie=UTF-8&total=1&idx=0&client=t"
2015-06-06 22:16:11 +02:00
local file = download_to_file(url)
2015-09-07 18:12:27 +02:00
if file == nil then
return "Google hat den Zugriff auf die API geblockt. URL: "..url
end
2015-06-06 22:16:11 +02:00
local cb_extra = {file_path=file}
send_audio(receiver, file, rmtmp_cb, cb_extra)
end
return {
2015-09-07 18:12:27 +02:00
description = "Text-To-Speech",
usage = {
"/tts [Text]: Sendet Sprachnachricht mit dem Text",
"/tts(Sprache) [Text]: Sendet Sprachnachricht in der Sprache mit dem Text (bspw. !ttsen Hello)"
},
patterns = {
2015-06-06 22:16:11 +02:00
"^/tts (.+)$",
"^/tts(%w+) (.+)$"
2015-09-07 18:12:27 +02:00
},
run = run
2015-06-06 22:16:11 +02:00
}