Wenet--离线语音识别 快速上手体验

  • 操作系统:Linux
  • GPU与CUDA:NVIDIA GeForce RTX 4090 D,CUDA 12.5

1. 新建python环境

bash 复制代码
conda create -n wenet_offline python=3.10 -y
conda activate wenet_offline

2. 安装 Wenet

WeNet 提供了封装好的 Python 包,安装极其简单。这只是一个运行时库,包含了预训练模型和推理接口,非常适合快速使用。它会自动安装核心依赖,如 PyTorch。如果想进行模型训练或深度定制,则需要克隆其源码仓库,但对于"仅使用"来说,这就够了

bash 复制代码
pip install git+https://gitcode.com/gh_mirrors/we/wenet

上面命令自动安装的 PyTorch /Numpy等版本兼容性有问题,重装下:

bash 复制代码
pip install torch==2.2.2+cu121 torchaudio==2.2.2+cu121 -f https://download.pytorch.org/whl/torch_stable.html

pip uninstall numpy -y
pip install "numpy<2"

3. 离线语音识别

python 复制代码
import wenet

model = wenet.load_model('paraformer')
result = model.transcribe('test_cn.wav')
print(result.text)

result = model.transcribe('test_en.wav')
print(result.text)

result = model.transcribe('test_mix.wav')
print(result.text)
python 复制代码
今天天气怎么样明天天气怎么样
what's your name hello who are you
hello你叫什么名字呀今天的天气怎么样ok bye

4. 多模型对比

python 复制代码
import wenet
import time

def test_models_compact():
    """紧凑格式测试模型"""
    
    audio_files = ['test_cn.wav', 'test_en.wav', 'test_mix.wav']
    models = ['paraformer', 'firered', 'whisper-large-v3', 'wenetspeech']
    
    print("模型对比测试 (格式: 模型-文件-时间-结果)")
    print("="*80)
    
    for model_name in models:
        try:
            model = wenet.load_model(model_name)
            
            for audio_file in audio_files:
                start = time.time()
                result = model.transcribe(audio_file)
                elapsed = time.time() - start
                
                result_text = result.text if hasattr(result, 'text') else str(result)
                # 单行输出
                print(f"{model_name:20} | {audio_file:15} | {elapsed:6.3f}s | {result_text}")
                
        except Exception as e:
            print(f"{model_name:20} | 失败: {e}")

if __name__ == "__main__":
    test_models_compact()
python 复制代码
模型对比测试 (格式: 模型-文件-时间-结果)
================================================================================
paraformer           | test_cn.wav     |  0.129s | 今天天气怎么样明天天气怎么样
paraformer           | test_en.wav     |  0.111s | what's your name hello who are you
paraformer           | test_mix.wav    |  0.222s | hello你叫什么名字呀今天的天气怎么样ok bye
firered              | test_cn.wav     |  0.913s | 今天天气怎么样明天天气怎么样
firered              | test_en.wav     |  0.784s | WHAT'S YOUR NAME HELLO WHO ARE YOU
firered              | test_mix.wav    |  1.747s | 哈喽你叫什么名字呀今天的天气怎么样 OK拜
whisper-large-v3     | test_cn.wav     |  2.057s |  How is the weather today? How is the weather tomorrow?
whisper-large-v3     | test_en.wav     |  1.454s |  What's your name? Hello, who are you?
whisper-large-v3     | test_mix.wav    |  2.786s |  Hello 你叫什么名字呀? 今天的天气怎么样? OK, bye.
wenetspeech          | test_cn.wav     |  0.067s | 今天天气怎么样明天天气怎么样
wenetspeech          | test_en.wav     |  0.066s | 我叫要耐姆你好胡油
wenetspeech          | test_mix.wav    |  0.130s | 你好你叫什么名字今天的天气怎么样好拜
相关推荐
FluxMelodySun3 分钟前
机器学习(三十三) 概率图模型与隐马尔可夫模型
人工智能·机器学习
深兰科技7 分钟前
深兰科技与淡水河谷合作推进:矿区示范加速落地
java·人工智能·python·c#·scala·symfony·深兰科技
V搜xhliang024612 分钟前
OpenClaw、AI大模型赋能数据分析与学术科研 学习
人工智能·深度学习·学习·机器学习·数据挖掘·数据分析
PHOSKEY13 分钟前
3D工业相机对焊后缺陷全检——机械手焊接系统质量控制的最后关口
人工智能
Aaron158815 分钟前
8通道测向系统演示科研套件
人工智能·算法·fpga开发·硬件工程·信息与通信·信号处理·基带工程
每天进步一点点️19 分钟前
AI芯片制造的“择优录用”:解读 APU Cluster4 的 Harvesting 机制
人工智能·soc片上系统·半导体芯片
AI医影跨模态组学20 分钟前
云南省肿瘤医院李振辉&广东省人民医院等团队:免疫表型引导的可解释放射组学模型预测III–IV期d-MMR/MSI-H结直肠癌新辅助抗PD-1治疗反应
人工智能·深度学习·论文·医学·医学影像
蒸汽求职26 分钟前
北美求职身份过渡:Day 1 CPT 的合规红线与安全入职指南
开发语言·人工智能·安全·pdf·github·开源协议
云烟成雨TD32 分钟前
Spring AI Alibaba 1.x 系列【18】Hook 接口和四大抽象类
java·人工智能·spring
大任视点37 分钟前
金博教育2026品牌升级:高端个性化辅导的“科技+教研”双引擎
人工智能