mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Add transcribe_audio method
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
3e36412e68
commit
0b220def26
6 changed files with 153 additions and 0 deletions
|
|
@ -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
|
||||
""",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
):
|
||||
|
|
|
|||
52
pyrogram/methods/messages/transcribe_audio.py
Normal file
52
pyrogram/methods/messages/transcribe_audio.py
Normal file
|
|
@ -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.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)
|
||||
|
|
@ -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"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
66
pyrogram/types/messages_and_media/transcribed_audio.py
Normal file
66
pyrogram/types/messages_and_media/transcribed_audio.py
Normal file
|
|
@ -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 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
|
||||
)
|
||||
Loading…
Reference in a new issue