local tts = {} function tts:init(config) tts.triggers = { "^/tts (.+)$", "^/tts(%w+) (.+)$" } tts.doc = [[* ]]..config.cmd_pat..[[tts* __: Sendet Sprachnachricht mit diesem Text *]]..config.cmd_pat..[[tts*__ __: Sendet Sprachnachricht mit diesem Text in der gewählten Sprache ]] end tts.command = 'tts ' 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 direkt?\n', 'HTML') return end utilities.send_voice(msg.chat.id, file, nil, msg.message_id) end return tts