diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 1f9365ee..34820205 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1762,7 +1762,9 @@ class Client: voice (``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 that exists on the Telegram servers, + pass an HTTP URL as a string for Telegram to get an audio from the Internet, or + pass a file path as string to upload a new audio that exists on your local machine. caption (``str``, optional): Voice message caption, 0-200 characters. @@ -1794,29 +1796,59 @@ 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(voice, progress=progress) + + if os.path.exists(voice): + file = self.save_file(voice, progress=progress) + media = types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + voice.split(".")[-1], "audio/mpeg"), + file=file, + attributes=[ + types.DocumentAttributeAudio( + voice=True, + duration=duration + ) + ] + ) + elif voice.startswith("http"): + media = types.InputMediaDocumentExternal( + url=voice + ) + else: + try: + decoded = utils.decode(voice) + fmt = " 24 else "