如何更改音频标题?

时间:2019-03-18 07:17:23

标签: python-3.x audio telegram-bot python-telegram-bot

我尝试使用电报机器人将音频文件发送给自己,然后上传到电报服务器并首先获取file_id:

response = requests.post(
url='https://api.telegram.org/bot{0}/{1}'.format(token, method),
data={'chat_id': v, 'audio': 
'http://www.largesound.com/ashborytour/sound/brobob.mp3'}).json()
print(response)

然后我得到了这个答复

{'duration': 29, 'mime_type': 'audio/mpeg', 'file_id': 
'CQADBAADCAADVt71UQINbAiCs0snAg', 'file_size': 355968}

如何使用自己的音频标题通过file_id重新发送音频?因为如果我这样做

response = requests.post(
url='https://api.telegram.org/bot{0}/{1}'.format(token, method),
data={'chat_id': v, 'audio': 'CQADBAADCAADVt71UQINbAiCs0snAg', 'title': 'Awesome bass', 'perfomer': 'Bass'}).json()

我从我的机器人中获得了名称为brobob.mp3的mp3文件,因此更改标题无效。我做错了什么?或者我该怎么做?

1 个答案:

答案 0 :(得分:0)

好吧,十五分钟,这就是答案(使用PyTelegramBotApi):

file_id = response['result']['audio']['file_id']
path = bot.get_file(file_id)
file = path.file_path
download = bot.download_file(file)
bot.send_audio(chat_id=v, audio=download, title="Awesome bass", 
performer="Bass", duration=120)