需要从Telegram上的Python下载语音消息

问题描述 投票:0回答:1

我开始开发一个与电报机器人有关的宠物项目。问题之一就是问题,如何从漫游器下载语音消息?

任务:需要从电报bot下载音频文件并保存在项目文件夹中。

GetUpdateshttps://api.telegram.org/bot/ getUpdates:

{"duration":2,"mime_type":"audio/ogg","file_id":"<file_id>","file_unique_id":"<file_unique_id>","file_size":8858}}}]}

我检查了[[pyTelegramBotAPI文档]],但是没有找到有关如何下载文件的说明。我根据文档创建了代码:

@bot.message_handler(content_types=['voice']) def voice_processing(message): file_info = bot.get_file(message.voice.file_id) file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(cfg.TOKEN, file_info.file_path))

print(type(file), file)
------------------------------------------------------------
Output: <class 'requests.models.Response'>, <Response [200]>
我还找到了一个

example

,作者在其中下载了[[chunks中的音频。我怎么不明白,但是它使用了一个[[类似函数:def read_chunks(chunk_size, bytes): while True: chunk = bytes[:chunk_size] bytes = bytes[chunk_size:] yield chunk if not bytes: break 我开始开发一个与电报机器人有关的宠物项目。问题之一是问题,如何从机器人下载语音消息?任务:需要从电报bot下载音频文件,然后...
python python-requests telegram telegram-bot python-telegram-bot
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.