feat: fix pcm

This commit is contained in:
Harold 2025-11-10 19:04:59 +08:00
parent 0b03e9a3f0
commit c86af104b4

View file

@ -12,7 +12,8 @@ from io import BytesIO
from core.utils import p3 from core.utils import p3
from pydub import AudioSegment from pydub import AudioSegment
from typing import Callable, Any from typing import Callable, Any
from config.logger import setup_logging
logger = setup_logging()
TAG = __name__ TAG = __name__
emoji_map = { emoji_map = {
"neutral": "😶", "neutral": "😶",
@ -317,13 +318,12 @@ def audio_bytes_to_data_stream(audio_bytes, file_type, is_opus, callback: Callab
""" """
transfer audio bytes to opus/pcm data, support wav、mp3、p3、pcm transfer audio bytes to opus/pcm data, support wav、mp3、p3、pcm
""" """
logger.bind(tag=TAG).info(f"audio_bytes_to_data_stream: {file_type}")
if file_type == "p3": if file_type == "p3":
# 直接用p3解码 # 直接用p3解码
return p3.decode_opus_from_bytes_stream(audio_bytes, callback) return p3.decode_opus_from_bytes_stream(audio_bytes, callback)
elif file_type == "pcm": elif file_type == "pcm":
audio = AudioSegment.from_raw( return pcm_to_data_stream(audio_bytes, is_opus, callback)
BytesIO(audio_bytes),
)
else: else:
# other formats use pydub # other formats use pydub
audio = AudioSegment.from_file( audio = AudioSegment.from_file(