Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentAttributeAudio ignored voice=False with io.BytesIO() object #4170

Open
3 tasks done
Platon2612 opened this issue Aug 8, 2023 · 2 comments
Open
3 tasks done

Comments

@Platon2612
Copy link

Platon2612 commented Aug 8, 2023

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

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.
@NotStatilko
Copy link
Contributor

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.

@Platon2612
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants