TTS-Plugin portiert
This commit is contained in:
parent
07143e914d
commit
47b79725c8
50
miku/plugins/tts.lua
Normal file
50
miku/plugins/tts.lua
Normal file
@ -0,0 +1,50 @@
|
||||
local tts = {}
|
||||
|
||||
function tts:init(config)
|
||||
tts.triggers = {
|
||||
"^/tts (.+)$",
|
||||
"^/tts(%w+) (.+)$"
|
||||
}
|
||||
tts.doc = [[*
|
||||
]]..config.cmd_pat..[[tts* _<Text>_: Sendet Sprachnachricht mit diesem Text
|
||||
*]]..config.cmd_pat..[[tts*_<Sprachcode>_ _<Text>_: Sendet Sprachnachricht mit diesem Text in der gewählten Sprache
|
||||
]]
|
||||
end
|
||||
|
||||
tts.command = 'tts <Text>'
|
||||
|
||||
function tts:action(msg, config, matches)
|
||||
if matches[2] == nil then
|
||||
text = matches[1]
|
||||
lang = 'de'
|
||||
else
|
||||
text = matches[2]
|
||||
lang = matches[1]
|
||||
end
|
||||
|
||||
local text = string.gsub(text, "%+", "plus")
|
||||
|
||||
local text = string.gsub(text, "%s+", "+")
|
||||
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")
|
||||
local text = string.gsub(text, "%&", "und")
|
||||
if string.len(text) > 160 then utilities.send_reply(msg, 'Text zu lang!') return end
|
||||
local text = string.gsub(text, " ", "+")
|
||||
|
||||
local url = 'http://tts.baidu.com/text2audio?lan='..lang..'&ie=UTF-8&text='..text
|
||||
utilities.send_typing(msg.chat.id, 'record_audio')
|
||||
local file = download_to_file(url, text..'.mp3')
|
||||
if not file then
|
||||
utilities.send_reply(msg, 'Ein Fehler ist aufgetreten, besuche die URL eventuell <a href="'..url..'">direkt</a>?\n', 'HTML')
|
||||
return
|
||||
end
|
||||
|
||||
utilities.send_voice(msg.chat.id, file, msg.message_id)
|
||||
end
|
||||
|
||||
return tts
|
Reference in New Issue
Block a user