|
2 | 2 | import re |
3 | 3 | import sys |
4 | 4 | import uuid |
| 5 | +import os |
5 | 6 |
|
6 | 7 | from apscheduler.schedulers.asyncio import AsyncIOScheduler |
7 | 8 | from telegram import BotCommand, Update |
|
21 | 22 | register_platform_adapter, |
22 | 23 | ) |
23 | 24 | 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 |
24 | 27 | from astrbot.core.star.filter.command import CommandFilter |
25 | 28 | from astrbot.core.star.filter.command_group import CommandGroupFilter |
26 | 29 | from astrbot.core.star.star import star_map |
27 | 30 | 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 |
28 | 32 |
|
29 | 33 | from .tg_event import TelegramPlatformEvent |
30 | 34 |
|
@@ -375,8 +379,19 @@ async def convert_message( |
375 | 379 |
|
376 | 380 | elif update.message.voice: |
377 | 381 | 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 | + |
378 | 393 | message.message = [ |
379 | | - Comp.Record(file=file.file_path, url=file.file_path), |
| 394 | + Comp.Record(file=path_wav, url=path_wav), |
380 | 395 | ] |
381 | 396 |
|
382 | 397 | elif update.message.photo: |
|
0 commit comments