Skip to content

Commit b54b4c7

Browse files
fix: Telegram voice message format (OGG instead of WAV) causing issues with OpenAI STT API (#5389)
1 parent c6cc7aa commit b54b4c7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

astrbot/core/platform/sources/telegram/tg_adapter.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import sys
44
import uuid
5+
import os
56

67
from apscheduler.schedulers.asyncio import AsyncIOScheduler
78
from telegram import BotCommand, Update
@@ -21,10 +22,13 @@
2122
register_platform_adapter,
2223
)
2324
from astrbot.core.platform.astr_message_event import MessageSesion
25+
from astrbot.core.utils.astrbot_path import get_astrbot_temp_path
26+
from astrbot.core.utils.media_utils import convert_audio_to_wav
2427
from astrbot.core.star.filter.command import CommandFilter
2528
from astrbot.core.star.filter.command_group import CommandGroupFilter
2629
from astrbot.core.star.star import star_map
2730
from astrbot.core.star.star_handler import star_handlers_registry
31+
from astrbot.core.utils.io import download_file, download_image_by_url, file_to_base64
2832

2933
from .tg_event import TelegramPlatformEvent
3034

@@ -375,8 +379,19 @@ async def convert_message(
375379

376380
elif update.message.voice:
377381
file = await update.message.voice.get_file()
382+
383+
file_basename = os.path.basename(file.file_path)
384+
temp_dir = get_astrbot_temp_path()
385+
temp_path = os.path.join(temp_dir, file_basename)
386+
temp_path = await download_image_by_url(file.file_path, path=temp_path)
387+
path_wav = os.path.join(
388+
temp_dir,
389+
f"{file_basename}.wav",
390+
)
391+
path_wav = await convert_audio_to_wav(temp_path, path_wav)
392+
378393
message.message = [
379-
Comp.Record(file=file.file_path, url=file.file_path),
394+
Comp.Record(file=path_wav, url=path_wav),
380395
]
381396

382397
elif update.message.photo:

0 commit comments

Comments
 (0)