我有一个关于python电报机器人的语音信息的问题。如何从用户获取语音,并在python-telegram-bot中处理此语音?
发布于 2019-11-25 22:18:59
尝试在语音文件处理程序中执行类似操作
def voice_handler(update, context):
bot = context.bot
file = bot.getFile(update.message.voice.file_id)
file.download('voice.mp3')在main函数中设置MessageHandler,如下所示:
def main():
updater = Updater(token=lashi_bot,use_context=True)
updater.dispatcher.add_handler(MessageHandler(Filters.voice, voice_handler))正如你在这个例子中看到的,你可以从下面的代码中获得file_id(语音):
update.message.voice.file_id你需要的一切都在update中,你可以在你的函数中打印update,如下所示:
def voice_handler(update, context):
bot = context.bot
file = bot.getFile(update.message.voice.file_id)
print(update)
file.download('voice.mp3')你可以看到里面有什么,它是很有用的
https://stackoverflow.com/questions/57761964
复制相似问题