From 83a89e79ded13c9bb15aadab7651f19afcd71de5 Mon Sep 17 00:00:00 2001 From: Shrimadhav U K Date: Fri, 9 Feb 2024 18:24:22 +0530 Subject: [PATCH] Fix `send_audio` not working as expected (#23) --- pyrogram/methods/messages/send_audio.py | 10 ++++++++-- pyrogram/methods/messages/send_voice.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/messages/send_audio.py b/pyrogram/methods/messages/send_audio.py index 95a20fc0..5f85eb79 100644 --- a/pyrogram/methods/messages/send_audio.py +++ b/pyrogram/methods/messages/send_audio.py @@ -197,10 +197,13 @@ class SendAudio: try: if isinstance(audio, str): if os.path.isfile(audio): + mime_type = self.guess_mime_type(audio) or "audio/mpeg" + if mime_type == "audio/ogg": + mime_type = "audio/opus" thumb = await self.save_file(thumb) file = await self.save_file(audio, progress=progress, progress_args=progress_args) media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(audio) or "audio/mpeg", + mime_type=mime_type, file=file, thumb=thumb, attributes=[ @@ -219,10 +222,13 @@ class SendAudio: else: media = utils.get_input_media_from_file_id(audio, FileType.AUDIO) else: + mime_type = self.guess_mime_type(file_name or audio.name) or "audio/mpeg" + if mime_type == "audio/ogg": + mime_type = "audio/opus" thumb = await self.save_file(thumb) file = await self.save_file(audio, progress=progress, progress_args=progress_args) media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(file_name or audio.name) or "audio/mpeg", + mime_type=mime_type, file=file, thumb=thumb, attributes=[ diff --git a/pyrogram/methods/messages/send_voice.py b/pyrogram/methods/messages/send_voice.py index b0c249b4..ee8c4f45 100644 --- a/pyrogram/methods/messages/send_voice.py +++ b/pyrogram/methods/messages/send_voice.py @@ -176,9 +176,12 @@ class SendVoice: try: if isinstance(voice, str): if os.path.isfile(voice): + mime_type = self.guess_mime_type(voice) or "audio/ogg" + if mime_type == "audio/mpeg": + mime_type = "audio/ogg" file = await self.save_file(voice, progress=progress, progress_args=progress_args) media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(voice) or "audio/mpeg", + mime_type=mime_type, file=file, attributes=[ raw.types.DocumentAttributeAudio( @@ -195,9 +198,12 @@ class SendVoice: else: media = utils.get_input_media_from_file_id(voice, FileType.VOICE) else: + mime_type = self.guess_mime_type(voice.name) or "audio/ogg" + if mime_type == "audio/mpeg": + mime_type = "audio/ogg" file = await self.save_file(voice, progress=progress, progress_args=progress_args) media = raw.types.InputMediaUploadedDocument( - mime_type=self.guess_mime_type(voice.name) or "audio/mpeg", + mime_type=mime_type, file=file, attributes=[ raw.types.DocumentAttributeAudio(