语音转文字(STT,Speech to Text)是人机交互、音视频处理、智能客服等领域的核心技术,Python 凭借生态丰富、易用性强的优势,成为 STT 开发的主流语言。本文聚焦 Python 生态中常用、成熟、高实用性的 STT 语音识别库,从功能特性、识别精度、部署成本、适用场景等维度展开盘点,为开发者选型提供清晰参考。
1 PaddleSpeech
PaddleSpeech 是百度飞桨开源的语音交互工具集,主打中文语音识别 / 合成能力,依托飞桨框架的高性能计算优势,在中文普通话、低音质音频识别场景下表现优异,且支持私有化部署,是企业级中文 STT 场景的首选方案之一。
1.1 安装步骤
conda create -n paddlespeech python=3.10
conda activate paddlespeech
python -m pip install paddlepaddle-gpu==3.2.2 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
注:如果这里没有 n 卡,这里修改成 pip install paddlepaddle,具体安装选择可以看官网:PaddlePaddle
我这里之所以使用源码编译的方式去安装,是因为直接使用 pip 安装会有很多 bug。
1.2 测试代码
import paddle
from paddlespeech.cli.asr import ASRExecutor
asr_executor = ASRExecutor()
text = asr_executor(audio_file="test.wav", model="conformer_aishell")
print(text)
1.3 遇到的报错
ERROR: Could not find a version that satisfies the requirement opencc==1.1.6 (from paddlespeech) (from versions: 0.1, 0.2, 1.1.0.post1, 1.1.1, 1.1.7, 1.1.8, 1.1.9) ERROR: No matching distribution found for opencc==1.1.6
直接去 PaddleSpeech/setup.py 下面修改 opencc 安装版本。
2 Whisper
Whisper 是 OpenAI 开源的多语言语音识别模型,凭借海量多语言音频数据训练,支持 99 种语言识别,中文普通话识别准确率≈95%,且抗噪能力强,是个人开发、多语言场景的首选方案。
2.1 安装命令
conda create -n whisper_env python=3.10
conda activate whisper_env
pip install -U openai-whisper
2.2 测试代码
import whisper
model = whisper.load_model("turbo")
result = model.transcribe("audio.mp3")
print(result["text"])
如下图所示,load_model 时,可选参数为:


