From d0d47b1a9e1f6cfeb6444d4e0eb0d96aed0632fe Mon Sep 17 00:00:00 2001 From: Yunhao Cao <18230652+realquantumcookie@users.noreply.github.com> Date: Mon, 23 Feb 2026 16:40:39 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DTelegram=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/telegram/tg_adapter.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index 03ef26c1e..abf6a09ad 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -2,6 +2,7 @@ import re import sys import uuid +import os from apscheduler.schedulers.asyncio import AsyncIOScheduler from telegram import BotCommand, Update @@ -21,10 +22,13 @@ register_platform_adapter, ) from astrbot.core.platform.astr_message_event import MessageSesion +from astrbot.core.utils.astrbot_path import get_astrbot_temp_path +from astrbot.core.utils.media_utils import convert_audio_to_wav from astrbot.core.star.filter.command import CommandFilter from astrbot.core.star.filter.command_group import CommandGroupFilter from astrbot.core.star.star import star_map from astrbot.core.star.star_handler import star_handlers_registry +from astrbot.core.utils.io import download_file, download_image_by_url, file_to_base64 from .tg_event import TelegramPlatformEvent @@ -375,8 +379,19 @@ async def convert_message( elif update.message.voice: file = await update.message.voice.get_file() + + file_basename = os.path.basename(file.file_path) + temp_dir = get_astrbot_temp_path() + temp_path = os.path.join(temp_dir, file_basename) + temp_path = await download_image_by_url(file.file_path, path=temp_path) + path_wav = os.path.join( + temp_dir, + f"{file_basename}.wav", + ) + path_wav = await convert_audio_to_wav(temp_path, path_wav) + message.message = [ - Comp.Record(file=file.file_path, url=file.file_path), + Comp.Record(file=path_wav, url=path_wav), ] elif update.message.photo: