Fix send_audio not working as expected (#23)

This commit is contained in:
Shrimadhav U K 2024-02-09 18:24:22 +05:30 committed by GitHub
parent 13070fe748
commit 83a89e79de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -197,10 +197,13 @@ class SendAudio:
try: try:
if isinstance(audio, str): if isinstance(audio, str):
if os.path.isfile(audio): 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) thumb = await self.save_file(thumb)
file = await self.save_file(audio, progress=progress, progress_args=progress_args) file = await self.save_file(audio, progress=progress, progress_args=progress_args)
media = raw.types.InputMediaUploadedDocument( media = raw.types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(audio) or "audio/mpeg", mime_type=mime_type,
file=file, file=file,
thumb=thumb, thumb=thumb,
attributes=[ attributes=[
@ -219,10 +222,13 @@ class SendAudio:
else: else:
media = utils.get_input_media_from_file_id(audio, FileType.AUDIO) media = utils.get_input_media_from_file_id(audio, FileType.AUDIO)
else: 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) thumb = await self.save_file(thumb)
file = await self.save_file(audio, progress=progress, progress_args=progress_args) file = await self.save_file(audio, progress=progress, progress_args=progress_args)
media = raw.types.InputMediaUploadedDocument( media = raw.types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(file_name or audio.name) or "audio/mpeg", mime_type=mime_type,
file=file, file=file,
thumb=thumb, thumb=thumb,
attributes=[ attributes=[

View File

@ -176,9 +176,12 @@ class SendVoice:
try: try:
if isinstance(voice, str): if isinstance(voice, str):
if os.path.isfile(voice): 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) file = await self.save_file(voice, progress=progress, progress_args=progress_args)
media = raw.types.InputMediaUploadedDocument( media = raw.types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(voice) or "audio/mpeg", mime_type=mime_type,
file=file, file=file,
attributes=[ attributes=[
raw.types.DocumentAttributeAudio( raw.types.DocumentAttributeAudio(
@ -195,9 +198,12 @@ class SendVoice:
else: else:
media = utils.get_input_media_from_file_id(voice, FileType.VOICE) media = utils.get_input_media_from_file_id(voice, FileType.VOICE)
else: 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) file = await self.save_file(voice, progress=progress, progress_args=progress_args)
media = raw.types.InputMediaUploadedDocument( media = raw.types.InputMediaUploadedDocument(
mime_type=self.guess_mime_type(voice.name) or "audio/mpeg", mime_type=mime_type,
file=file, file=file,
attributes=[ attributes=[
raw.types.DocumentAttributeAudio( raw.types.DocumentAttributeAudio(