Skip to content

Commit

Permalink
fixed:ModuleNotFoundError: No module named 'opuslib' (#121)
Browse files Browse the repository at this point in the history
Co-authored-by: hrz <[email protected]>
  • Loading branch information
xinnan-tech and openrz authored Feb 23, 2025
1 parent 2d01812 commit 22ff7a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions core/providers/asr/doubao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -120,4 +120,4 @@ def check_password(password):
return False

# 如果满足所有条件,则返回True
return True
return True

0 comments on commit 22ff7a9

Please sign in to comment.