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: