我正在尝试使用 python 和 python-telegram-bot 包构建一个电报机器人,它现在使用文本命令我尝试向用户发送语音命令..
我的代码喜欢
def start(update, context):
engine = pyttsx3.init()
engine.save_to_file('welcome to this bot', 'voice.mp3')
engine.runAndWait()
#return update.message.reply_text('hi i am bot with your friend')
生成了mp3文件,那么如何将该语音文件发送给用户呢?
答案 0 :(得分:2)
您要查找的方法在 official API docs 中称为 sendVoice
。对于 PTB,它是 Bot.send_voice
。另请参阅 Message.reply_voice
快捷方式和有关在 PTB 中处理文件的 wiki entry。
免责声明:我目前是 python-telegram-bot
的维护者。