如何使用电视发送音频文件,以便可以在移动应用内媒体播放器中播放音频



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

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)])

我想发送一个可以使用应用内音频播放的音频游戏者

好的,你只需要使用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())

client.send_file(聊天,'/my/songs/song.mp3',voice_note=True(

测试这个,它将音频作为用户记录发送,没有"voice_note=True",媒体作为主文件发送

我不知道您是否仍然有这个问题,但我通过安装带有pip install hachoir的hachoir模块解决了这个问题。基本上问题是客户端没有必要的元数据

我遇到了与作者相同的情况,因为我的mp3文件没有扩展名(我使用了临时文件(。

您的情况的原因可以在send_file方法代码中找到。在我的案例中,我发现如果我在调试模式下为send_file/self._file_to_media中的媒体设置mime类型audio/mpeg,它会将文件作为应用内音频发送。所以我发现该方法无法猜测我的文件mime类型。我向前搜索,找到了解决方案。

而且。。。我尝试了voice_note=True——在我的情况下,它没有帮助,因为我的文件不是语音,而是mp3。事实上,当我下载它时,它已经设置了voice_note=False。因此,如果您处理的音频文件不是语音,则将voice_note设置为True没有任何意义。

最新更新