From 22ff7a92b87d8e85e29163ef33d6a0e54df9eb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A3=E5=8D=97=E7=A7=91=E6=8A=80?= Date: Sun, 23 Feb 2025 19:59:26 +0800 Subject: [PATCH] fixed:ModuleNotFoundError: No module named 'opuslib' (#121) Co-authored-by: hrz <1710360675@qq.com> --- core/providers/asr/doubao.py | 10 +++++----- core/utils/util.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/providers/asr/doubao.py b/core/providers/asr/doubao.py index 5610807..a5a5bb6 100644 --- a/core/providers/asr/doubao.py +++ b/core/providers/asr/doubao.py @@ -8,7 +8,7 @@ import json import gzip -import opuslib +import opuslib_next from core.providers.asr.base import ASRProviderBase from config.logger import setup_logging @@ -103,14 +103,14 @@ def save_audio_to_file(self, opus_data: List[bytes], session_id: str) -> str: file_name = f"asr_{session_id}_{uuid.uuid4()}.wav" file_path = os.path.join(self.output_dir, file_name) - decoder = opuslib.Decoder(16000, 1) # 16kHz, 单声道 + decoder = opuslib_next.Decoder(16000, 1) # 16kHz, 单声道 pcm_data = [] for opus_packet in opus_data: try: pcm_frame = decoder.decode(opus_packet, 960) # 960 samples = 60ms pcm_data.append(pcm_frame) - except opuslib.OpusError as e: + except opuslib_next.OpusError as e: logger.bind(tag=TAG).error(f"Opus解码错误: {e}", exc_info=True) with wave.open(file_path, "wb") as wf: @@ -216,14 +216,14 @@ async def _send_request(self, audio_data: List[bytes], segment_size: int) -> Opt @staticmethod def decode_opus(opus_data: List[bytes], session_id: str) -> List[bytes]: - decoder = opuslib.Decoder(16000, 1) # 16kHz, 单声道 + decoder = opuslib_next.Decoder(16000, 1) # 16kHz, 单声道 pcm_data = [] for opus_packet in opus_data: try: pcm_frame = decoder.decode(opus_packet, 960) # 960 samples = 60ms pcm_data.append(pcm_frame) - except opuslib.OpusError as e: + except opuslib_next.OpusError as e: logger.bind(tag=TAG).error(f"Opus解码错误: {e}", exc_info=True) return pcm_data diff --git a/core/utils/util.py b/core/utils/util.py index 0c1b5b6..19495c3 100644 --- a/core/utils/util.py +++ b/core/utils/util.py @@ -90,7 +90,7 @@ def remove_punctuation_and_length(text): char not in full_width_punctuations and char not in half_width_punctuations and char not in space and char not in full_width_space]) if result == "Yeah": - return 0 + return 0, "" return len(result), result @@ -120,4 +120,4 @@ def check_password(password): return False # 如果满足所有条件,则返回True - return True \ No newline at end of file + return True