首页 > 解决方案 > 如何使用 Telethon 发送音频文件,以便可以在移动应用内媒体播放器中播放音频?

问题描述

我尝试使用这两个功能,音频仍然无法在应用媒体播放器中播放

await client.send_file(chat, '/my/songs/song.mp3', voice_note=True)

await client.send_file(chat, '/my/songs/song.mp3', attributes=[DocumentAttributeFilename(file_name=fileName + '.mp3'), DocumentAttributeAudio(duration=100, voice=True)])

标签: telethon

解决方案


我正在寻找可以使用应用内音频播放器播放的音频。

好的,您只需要在此处send_file的库文档中使用 , 参考。

import asyncio
from telethon import TelegramClient

client = TelegramClient('SESSION_NAME', 'YOUR_API_ID', 'YOUR_API_HASH')
client.start(phone=+xxxxxxxxxxxx)

async def main():
    await client.send_file('me', 'test.mp3')

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

推荐阅读