Telethon
Telethon copied to clipboard
DocumentAttributeAudio ignored voice=False with io.BytesIO() object
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
- [X] The error is in the library's code, and not in my own.
- [X] I have searched for this issue before posting it and there isn't an open duplicate.
- [X] I ran
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zipand triggered the bug in the latest version.
Try the force_document keyword for send_file
https://docs.telethon.dev/en/stable/modules/client.html#telethon.client.uploads.UploadMethods.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.