mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Fix send_audio
not working as expected (#23)
This commit is contained in:
parent
13070fe748
commit
83a89e79de
@ -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=[
|
||||||
|
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user