From 02d5bb0f8c912071de41afcbe7fb73f8080908d1 Mon Sep 17 00:00:00 2001 From: kalicyh <34980061+kaliCYH@users.noreply.github.com> Date: Tue, 18 Feb 2025 20:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:=20=E6=94=B9=E7=94=A8opusli?= =?UTF-8?q?b=5Fnext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/providers/tts/base.py | 4 ++-- core/utils/asr.py | 6 +++--- core/utils/vad.py | 6 +++--- poetry.lock | 9 +++++---- pyproject.toml | 2 +- requirements.txt | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/providers/tts/base.py b/core/providers/tts/base.py index 54438f312..84737608e 100644 --- a/core/providers/tts/base.py +++ b/core/providers/tts/base.py @@ -2,7 +2,7 @@ import asyncio from config.logger import setup_logging import os import numpy as np -import opuslib +import opuslib_next from pydub import AudioSegment from abc import ABC, abstractmethod @@ -58,7 +58,7 @@ class TTSProviderBase(ABC): raw_data = audio.raw_data # 初始化Opus编码器 - encoder = opuslib.Encoder(16000, 1, opuslib.APPLICATION_AUDIO) + encoder = opuslib_next.Encoder(16000, 1, opuslib_next.APPLICATION_AUDIO) # 编码参数 frame_duration = 60 # 60ms per frame diff --git a/core/utils/asr.py b/core/utils/asr.py index 1c23fe551..c6840f7f8 100644 --- a/core/utils/asr.py +++ b/core/utils/asr.py @@ -6,7 +6,7 @@ from config.logger import setup_logging from typing import Optional, Tuple, List import uuid -import opuslib +import opuslib_next from funasr import AutoModel from funasr.utils.postprocess_utils import rich_transcription_postprocess @@ -47,14 +47,14 @@ class FunASR(ASR): 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: diff --git a/core/utils/vad.py b/core/utils/vad.py index 05e11eb52..ef782281c 100644 --- a/core/utils/vad.py +++ b/core/utils/vad.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod from config.logger import setup_logging -import opuslib +import opuslib_next import time import numpy as np import torch @@ -24,7 +24,7 @@ class SileroVAD(VAD): force_reload=False) (get_speech_timestamps, _, _, _, _) = self.utils - self.decoder = opuslib.Decoder(16000, 1) + self.decoder = opuslib_next.Decoder(16000, 1) self.vad_threshold = config.get("threshold") self.silence_threshold_ms = config.get("min_silence_duration_ms") @@ -59,7 +59,7 @@ class SileroVAD(VAD): conn.client_have_voice_last_time = time.time() * 1000 return client_have_voice - except opuslib.OpusError as e: + except opuslib_next.OpusError as e: logger.bind(tag=TAG).info(f"解码错误: {e}") except Exception as e: logger.bind(tag=TAG).error(f"Error processing audio packet: {e}") diff --git a/poetry.lock b/poetry.lock index 3d5366d88..8e2114bae 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2202,14 +2202,15 @@ datalib = ["numpy (>=1)", "pandas (>=1.2.3)", "pandas-stubs (>=1.1.0.11)"] realtime = ["websockets (>=13,<15)"] [[package]] -name = "opuslib" -version = "3.0.1" +name = "opuslib-next" +version = "1.1.2" description = "Python bindings to the libopus, IETF low-delay audio codec" optional = false python-versions = "*" groups = ["main"] files = [ - {file = "opuslib-3.0.1.tar.gz", hash = "sha256:2cb045e5b03e7fc50dfefe431e3404dddddbd8f5961c10c51e32dfb69a044c97"}, + {file = "opuslib_next-1.1.2-py2.py3-none-any.whl", hash = "sha256:adc432290ed721febff19dc0deb3b0cdbe846e80cd79fec742a7d47d960f13ed"}, + {file = "opuslib_next-1.1.2.tar.gz", hash = "sha256:d44a63c69783ab3ccaf349d46a1e37741eb620d6391461a18f95ac1b538e6796"}, ] [[package]] @@ -3731,4 +3732,4 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.1" python-versions = "^3.10.16" -content-hash = "a4198be98d482e4393ef98f074b2c62c59786c8ef679adc2285473d1b9eb7d92" +content-hash = "9d724dd1cc50a7a6a42f0b5d8a81ad788332939ffc6a3ba12537106567f4ebe7" diff --git a/pyproject.toml b/pyproject.toml index eb5a97184..2ee2fc148 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,6 @@ pyyml = "0.0.2" torch = "2.2.2" silero-vad = "5.1.2" websockets = "14.2" -opuslib = "3.0.1" numpy = "1.26.4" pydub = "0.25.1" funasr = "1.2.3" @@ -26,6 +25,7 @@ ormsgpack = "1.7.0" ruamel-yaml = "0.18.10" setuptools = "^75.8.0" loguru = "^0.7.3" +opuslib-next = "^1.1.2" [build-system] diff --git a/requirements.txt b/requirements.txt index 46636a22a..be5663068 100755 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ pyyml==0.0.2 torch==2.2.2 silero_vad==5.1.2 websockets==14.2 -opuslib==3.0.1 +opuslib_next==1.1.2 numpy==1.26.4 pydub==0.25.1 funasr==1.2.3