From b54b4c79edcd6d3ad1f5838a8dde4d5eafa04482 Mon Sep 17 00:00:00 2001 From: Yunhao Cao <18230652+realquantumcookie@users.noreply.github.com> Date: Tue, 24 Feb 2026 15:11:56 +0000 Subject: [PATCH] fix: Telegram voice message format (OGG instead of WAV) causing issues with OpenAI STT API (#5389) --- .../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 asyncio import re import sys import uuid +import os from apscheduler.schedulers.asyncio import AsyncIOScheduler from telegram import BotCommand, Update @@ -21,10 +22,13 @@ from astrbot.api.platform import ( 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 @@ class TelegramPlatformAdapter(Platform): 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: