Skip to content

Commit baa27a0

Browse files
committed
pyrofork: Add transcribe_audio method
Signed-off-by: wulan17 <wulan17@nusantararom.org>
1 parent bd340cd commit baa27a0

File tree

6 files changed

+153
-0
lines changed

6 files changed

+153
-0
lines changed

compiler/docs/compiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def get_title_list(s: str) -> list:
220220
get_discussion_replies
221221
get_discussion_replies_count
222222
get_custom_emoji_stickers
223+
transcribe_audio
223224
translate_message_text
224225
start_bot
225226
""",
@@ -534,6 +535,7 @@ def get_title_list(s: str) -> list:
534535
WebPage
535536
WebPageEmpty
536537
WebPagePreview
538+
TranscribedAudio
537539
TranslatedText
538540
Poll
539541
PollOption
@@ -780,6 +782,7 @@ def get_title_list(s: str) -> list:
780782
Message.reply_web_page
781783
Message.get_media_group
782784
Message.react
785+
Message.transcribe
783786
Message.translate
784787
Message.wait_for_click
785788
""",

pyrogram/methods/messages/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from .stop_poll import StopPoll
7575
from .stream_media import StreamMedia
7676
from .vote_poll import VotePoll
77+
from .transcribe_audio import TranscribeAudio
7778
from .translate_text import TranslateText
7879

7980
class Messages(
@@ -133,6 +134,7 @@ class Messages(
133134
GetDiscussionRepliesCount,
134135
StreamMedia,
135136
GetCustomEmojiStickers,
137+
TranscribeAudio,
136138
TranslateText,
137139
StartBot
138140
):
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Pyrofork - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
4+
#
5+
# This file is part of Pyrofork.
6+
#
7+
# Pyrofork is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# Pyrofork is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
19+
20+
from typing import Union
21+
22+
import pyrogram
23+
from pyrogram import raw, types
24+
25+
26+
class TranscribeAudio:
27+
async def transcribe_audio(
28+
self: "pyrogram.Client",
29+
chat_id: Union[int, str],
30+
message_id: int
31+
) -> "types.TranscribeAudio":
32+
"""Transcribes the audio of a voice message.
33+
34+
Parameters:
35+
chat_id (``int`` | ``str``):
36+
Unique identifier (int) or username (str) of the target chat.
37+
38+
message_id (``int``):
39+
Identifier of the message containing the voice message.
40+
41+
Returns:
42+
:obj:`~pyrogram.types.TranscribeAudio`: On success.
43+
"""
44+
chat = await self.resolve_peer(chat_id)
45+
r = await self.invoke(
46+
raw.functions.messages.TranscribeAudio(
47+
peer=chat,
48+
msg_id=message_id
49+
)
50+
)
51+
52+
return types.TranscribeAudio._parse(r)

pyrogram/types/messages_and_media/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
from .exported_story_link import ExportedStoryLink
7070
from .wallpaper import Wallpaper
7171
from .wallpaper_settings import WallpaperSettings
72+
from .transcribed_audio import TranscribedAudio
7273
from .translated_text import TranslatedText
7374

7475
__all__ = [
@@ -124,5 +125,6 @@
124125
"ExportedStoryLink",
125126
"Wallpaper",
126127
"WallpaperSettings",
128+
"TranscribedAudio",
127129
"TranslatedText"
128130
]

pyrogram/types/messages_and_media/message.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5434,6 +5434,34 @@ async def ask(
54345434
reply_message.request = request
54355435
return reply_message
54365436

5437+
async def transcribe(self) -> "types.TranscribeAudio":
5438+
"""Bound method *transcribe* of :obj:`~pyrogram.types.Message`.
5439+
5440+
Use as a shortcut for:
5441+
5442+
.. code-block:: python
5443+
5444+
await client.transcribe_audio(
5445+
chat_id=message.chat.id,
5446+
message_id=message.id
5447+
)
5448+
5449+
Example:
5450+
.. code-block:: python
5451+
5452+
await message.transcribe()
5453+
5454+
Returns:
5455+
:obj:`~pyrogram.types.TranscribeAudio`: On success.
5456+
5457+
Raises:
5458+
RPCError: In case of a Telegram RPC error.
5459+
"""
5460+
return await self._client.transcribe_audio(
5461+
chat_id=self.chat.id,
5462+
message_id=self.id
5463+
)
5464+
54375465
async def translate(
54385466
self,
54395467
to_language_code: str
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Pyrofork - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
4+
#
5+
# This file is part of Pyrofork.
6+
#
7+
# Pyrofork is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# Pyrofork is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
19+
20+
from pyrogram import raw
21+
22+
23+
class TranscribeAudio:
24+
"""Transcribes the audio of a voice message.
25+
26+
Parameters:
27+
transcription_id (``int``):
28+
Unique identifier of the transcription.
29+
30+
text (``str``):
31+
Transcribed text.
32+
33+
pending (``bool``, *optional*):
34+
Whether the transcription is pending.
35+
36+
trial_remains_num (``int``, *optional*):
37+
Number of trials remaining.
38+
39+
trial_remains_until_date (``int``, *optional*):
40+
Date the trial remains until.
41+
"""
42+
43+
def __init__(
44+
self,
45+
*,
46+
transcription_id: int,
47+
text: str,
48+
pending: bool = None,
49+
trial_remains_num: int = None,
50+
trial_remains_until_date: int = None
51+
):
52+
self.transcription_id = transcription_id
53+
self.text = text
54+
self.pending = pending
55+
self.trial_remains_num = trial_remains_num
56+
self.trial_remains_until_date = trial_remains_until_date
57+
58+
@staticmethod
59+
def _parse(transcribe_result: "raw.types.messages.TranscribedAudio") -> "TranscribeAudio":
60+
return TranscribeAudio(
61+
transcription_id=transcribe_result.id,
62+
text=transcribe_result.text,
63+
pending=transcribe_result.pending,
64+
trial_remains_num=transcribe_result.trial_remains_num,
65+
trial_remains_until_date=transcribe_result.trial_remains_until_date
66+
)

0 commit comments

Comments
 (0)