pytest框架---fixture固件
2026/6/26 16:27:13
FRCRN(Frequency-Recurrent Convolutional Recurrent Network)是阿里巴巴达摩院在ModelScope社区开源的一款专业级语音降噪模型。这个16kHz单声道版本特别适合处理各种复杂环境下的语音降噪任务,能够有效分离人声与背景噪声。
确保您的系统满足以下最低配置:
pip install modelscope torchaudio注:首次安装会自动下载PyTorch等核心依赖
当您首次执行以下代码时,ModelScope会自动下载模型权重:
from modelscope.pipelines import pipeline ans_pipeline = pipeline( 'speech_frcrn_ans_cirm_16k', model='damo/speech_frcrn_ans_cirm_16k' )下载的模型默认保存在:
~/.cache/modelscope/hubC:\Users\<username>\.cache\modelscope\hub如需在无网络环境使用,请按以下步骤操作:
hub目录打包复制到目标机器相同路径export MODEL_SCOPE_CACHE=/path/to/your/hub确保输入音频符合要求:
使用ffmpeg进行格式转换:
ffmpeg -i input.mp3 -ar 16000 -ac 1 output.wavfrom modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks def denoise_audio(input_path, output_path): ans_pipeline = pipeline( Tasks.acoustic_noise_suppression, model='damo/speech_frcrn_ans_cirm_16k' ) result = ans_pipeline(input_path) with open(output_path, 'wb') as f: f.write(result['output_pcm'])import os input_dir = 'noisy_audios' output_dir = 'clean_audios' os.makedirs(output_dir, exist_ok=True) for file in os.listdir(input_dir): if file.endswith('.wav'): input_path = os.path.join(input_dir, file) output_path = os.path.join(output_dir, f"clean_{file}") denoise_audio(input_path, output_path)若需强制使用GPU,可指定设备参数:
ans_pipeline = pipeline( Tasks.acoustic_noise_suppression, model='damo/speech_frcrn_ans_cirm_16k', device='cuda:0' # 指定GPU设备 )现象:报错"Model not found"解决方案:
可能原因:
排查步骤:
import librosa y, sr = librosa.load('input.wav', sr=None) print(f"采样率: {sr}Hz, 声道数: {len(y.shape)}")# 实时音频流处理示例 import pyaudio import numpy as np CHUNK = 16000 # 1秒的音频块 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 16000 p = pyaudio.PyAudio() stream = p.open( format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK ) print("* 开始降噪处理...") while True: data = stream.read(CHUNK) audio = np.frombuffer(data, dtype=np.int16) # 此处添加降噪处理逻辑适合处理采访录音中的:
获取更多AI镜像
想探索更多AI镜像和应用场景?访问 CSDN星图镜像广场,提供丰富的预置镜像,覆盖大模型推理、图像生成、视频生成、模型微调等多个领域,支持一键部署。