diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 6cde6810..ede69577 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -220,6 +220,7 @@ def pyrogram_api(): get_discussion_replies get_discussion_replies_count get_custom_emoji_stickers + transcribe_audio translate_message_text start_bot """, @@ -534,6 +535,7 @@ def pyrogram_api(): WebPage WebPageEmpty WebPagePreview + TranscribedAudio TranslatedText Poll PollOption @@ -780,6 +782,7 @@ def pyrogram_api(): Message.reply_web_page Message.get_media_group Message.react + Message.transcribe Message.translate Message.wait_for_click """, diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index ab66ffac..1dde4137 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -74,6 +74,7 @@ from .start_bot import StartBot from .stop_poll import StopPoll from .stream_media import StreamMedia from .vote_poll import VotePoll +from .transcribe_audio import TranscribeAudio from .translate_text import TranslateText class Messages( @@ -133,6 +134,7 @@ class Messages( GetDiscussionRepliesCount, StreamMedia, GetCustomEmojiStickers, + TranscribeAudio, TranslateText, StartBot ): diff --git a/pyrogram/methods/messages/transcribe_audio.py b/pyrogram/methods/messages/transcribe_audio.py new file mode 100644 index 00000000..844e2967 --- /dev/null +++ b/pyrogram/methods/messages/transcribe_audio.py @@ -0,0 +1,52 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +from typing import Union + +import pyrogram +from pyrogram import raw, types + + +class TranscribeAudio: + async def transcribe_audio( + self: "pyrogram.Client", + chat_id: Union[int, str], + message_id: int + ) -> "types.TranscribedAudio": + """Transcribes the audio of a voice message. + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + + message_id (``int``): + Identifier of the message containing the voice message. + + Returns: + :obj:`~pyrogram.types.TranscribeAudio`: On success. + """ + chat = await self.resolve_peer(chat_id) + r = await self.invoke( + raw.functions.messages.TranscribeAudio( + peer=chat, + msg_id=message_id + ) + ) + + return types.TranscribedAudio._parse(r) diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 1acf6d5a..486f4664 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -69,6 +69,7 @@ from .story_views import StoryViews from .exported_story_link import ExportedStoryLink from .wallpaper import Wallpaper from .wallpaper_settings import WallpaperSettings +from .transcribed_audio import TranscribedAudio from .translated_text import TranslatedText __all__ = [ @@ -124,5 +125,6 @@ __all__ = [ "ExportedStoryLink", "Wallpaper", "WallpaperSettings", + "TranscribedAudio", "TranslatedText" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 5bee6645..f2de74ed 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -5434,6 +5434,34 @@ class Message(Object, Update): reply_message.request = request return reply_message + async def transcribe(self) -> "types.TranscribeAudio": + """Bound method *transcribe* of :obj:`~pyrogram.types.Message`. + + Use as a shortcut for: + + .. code-block:: python + + await client.transcribe_audio( + chat_id=message.chat.id, + message_id=message.id + ) + + Example: + .. code-block:: python + + await message.transcribe() + + Returns: + :obj:`~pyrogram.types.TranscribeAudio`: On success. + + Raises: + RPCError: In case of a Telegram RPC error. + """ + return await self._client.transcribe_audio( + chat_id=self.chat.id, + message_id=self.id + ) + async def translate( self, to_language_code: str diff --git a/pyrogram/types/messages_and_media/transcribed_audio.py b/pyrogram/types/messages_and_media/transcribed_audio.py new file mode 100644 index 00000000..c85d0b62 --- /dev/null +++ b/pyrogram/types/messages_and_media/transcribed_audio.py @@ -0,0 +1,66 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +from pyrogram import raw + + +class TranscribedAudio: + """Transcribes the audio of a voice message. + + Parameters: + transcription_id (``int``): + Unique identifier of the transcription. + + text (``str``): + Transcribed text. + + pending (``bool``, *optional*): + Whether the transcription is pending. + + trial_remains_num (``int``, *optional*): + Number of trials remaining. + + trial_remains_until_date (``int``, *optional*): + Date the trial remains until. + """ + + def __init__( + self, + *, + transcription_id: int, + text: str, + pending: bool = None, + trial_remains_num: int = None, + trial_remains_until_date: int = None + ): + self.transcription_id = transcription_id + self.text = text + self.pending = pending + self.trial_remains_num = trial_remains_num + self.trial_remains_until_date = trial_remains_until_date + + @staticmethod + def _parse(transcribe_result: "raw.types.messages.TranscribedAudio") -> "TranscribeAudio": + return TranscribedAudio( + transcription_id=transcribe_result.id, + text=transcribe_result.text, + pending=transcribe_result.pending, + trial_remains_num=transcribe_result.trial_remains_num, + trial_remains_until_date=transcribe_result.trial_remains_until_date + )