diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 74dfdafd..3576128a 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1214,7 +1214,9 @@ class Client: audio (``str``): Audio file to send. - Pass a file path as string to send an audio file that exists on your local machine. + Pass a file_id as string to send an audio file that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get an audio file from the Internet, or + pass a file path as string to upload a new audio file that exists on your local machine. caption (``str``, optional): Audio caption, 0-200 characters. @@ -1252,31 +1254,61 @@ class Client: The size of the file. Returns: - On success, the sent Message is returned. + On success, the sent :obj:`Message ` is returned. Raises: :class:`Error ` """ + file = None style = self.html if parse_mode.lower() == "html" else self.markdown - file = self.save_file(audio, progress=progress) + + if os.path.exists(audio): + file = self.save_file(audio, progress=progress) + media = types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"), + file=file, + attributes=[ + types.DocumentAttributeAudio( + duration=duration, + performer=performer, + title=title + ), + types.DocumentAttributeFilename(os.path.basename(audio)) + ] + ) + elif audio.startswith("http"): + media = types.InputMediaDocumentExternal( + url=audio + ) + else: + try: + decoded = decode(audio) + fmt = " 24 else "