Open Platon2612 opened 1 year ago
Try the force_document
keyword for send_file
Telegram voices is not an MP3
files, it's OGG
. Obviously audio.mp3
will be not voice.
I checked your option, send as a file, but the telethon.tl.types.DocumentAttribute Audio attribute is ignored and is displayed in the artist column as "Unknown artist".
`await client.send_file(entity=chat_id, caption="", file=img_byte_arr, force_document=True, voice_note=False, attributes=[telethon.tl.types.DocumentAttributeAudio(duration=10, title="Title", performer="Performer", voice=False)]) # Sends the audio document as needed but ignore telethon.tl.types.DocumentAttributeAudio
await client.send_file(entity=chat_id, caption="", file="audio.ogg", force_document=True, voice_note=False, attributes=[telethon.tl.types.DocumentAttributeAudio(duration=10, title="Title", performer="Performer", voice=False)]) # Sends the audio document as needed but ignore telethon.tl.types.DocumentAttributeAudio`
As I understand it, the voice_note flag is no longer required if the force_document=True flag is present.
Code that causes the issue
import io from gtts import gTTS
img_byte_arr = io.BytesIO() tts = gTTS(text=text, lang="ru", lang_check=True) tts.write_to_fp(img_byte_arr) img_byte_arr.name = "name.ogg" img_byte_arr.seek(0) await client.send_file(entity=chat_id, caption="", file=img_byte_arr, voice_note=False, attributes=[telethon.tl.types.DocumentAttributeAudio(duration=10, title="Title", performer="Performer", voice=False)]) # Sends only a voice message ignoring voice_note=False and voice=False (bug)
await client.send_file(entity=chat_id, caption="", file="audio.mp3", voice_note=False, attributes=[telethon.tl.types.DocumentAttributeAudio(duration=10, title="Title", performer="Performer", voice=False)]) # Sends the document as needed
await client.send_file(entity=chat_id, caption="", file=img_byte_arr, voice_note=False) # Sends the document as needed
Expected behavior
Must send as a file.
Actual behavior
When sending a BytesIO() object, the parameters of sending as a file are ignored (sent only as a voice message).
If you send a file recorded on disk, then audio is sent as a file (as needed).
Traceback
No response
Telethon version
1.28.5, 1.29.2
Python version
3.7
Operating system (including distribution name and version)
Ubuntu 18.04, Windows 8.1
Other details
No response
Checklist
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.