-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyrofork: Add transcribe_audio method
Signed-off-by: wulan17 <[email protected]>
- Loading branch information
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Pyrofork - Telegram MTProto API Client Library for Python | ||
# Copyright (C) 2017-present Dan <https://github.com/delivrance> | ||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>. | ||
|
||
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.TranscribeAudio": | ||
"""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.TranscribeAudio._parse(r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Pyrofork - Telegram MTProto API Client Library for Python | ||
# Copyright (C) 2017-present Dan <https://github.com/delivrance> | ||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>. | ||
|
||
from pyrogram import raw | ||
|
||
|
||
class TranscribeAudio: | ||
"""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 TranscribeAudio( | ||
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 | ||
) |