From 93e7e33c2fe11398fc0374883ffdf51bb59bae3d Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Tue, 21 Apr 2026 18:33:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DWebM=E9=9F=B3=E9=A2=91?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E6=94=AF=E6=8C=81=EF=BC=8C=E6=94=B9=E7=94=A8?= =?UTF-8?q?librosa=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/server.py b/server.py index 89d78f8..6c09515 100644 --- a/server.py +++ b/server.py @@ -82,18 +82,10 @@ def process_audio(audio_bytes: bytes) -> tuple: 处理音频文件 返回: (audio_array, sample_rate) """ - # 使用 soundfile 读取音频 audio_io = io.BytesIO(audio_bytes) - audio, sr = sf.read(audio_io) - # 转换为单声道 - if len(audio.shape) > 1: - audio = audio.mean(axis=1) - - # 重采样到 16kHz - if sr != SAMPLE_RATE: - import resampy - audio = resampy.resample(audio, sr, SAMPLE_RATE) + # 使用 librosa 读取音频(支持更多格式:WAV, WebM, MP3, FLAC 等) + audio, sr = librosa.load(audio_io, sr=SAMPLE_RATE, mono=True) return audio, SAMPLE_RATE