3分钟上手FunASR语音识别框架:从安装到实战全攻略
你是否还在为语音识别项目搭建环境而烦恼?本文将带你3分钟完成FunASR(Fundamental End-to-End Speech Recognition Toolkit,基础端到端语音识别工具包)的安装部署,涵盖Windows/Linux/Mac全平台,零基础也能轻松上手。读完本文你将掌握:环境配置、两种安装方式、Docker部署技巧及常见问题解决方法。
安装前准备
FunASR支持多操作系统和Python版本,具体环境要求如下:
- 操作系统:Linux、Windows、Mac
- Python版本:3.7-3.10
- Pytorch版本:≥1.11.0
推荐工具链
快速安装指南
方式一:PIP一键安装(推荐)
# 基础安装
pip3 install -U funasr
# 国内用户推荐使用镜像加速
pip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple
方式二:源码编译安装
# 克隆仓库
git clone https://gitcode.com/GitHub_Trending/fun/FunASR && cd FunASR
# 源码安装
pip3 install -e ./ -i https://mirror.sjtu.edu.cn/pypi/web/simple
环境配置详解
Conda虚拟环境配置(可选)
Linux/Mac系统
# 下载Miniconda
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
# 安装并激活环境
sh Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc
conda create -n funasr python=3.8
conda activate funasr
Windows系统
请参考Miniconda官方文档下载安装包,双击运行后按向导完成安装。
Pytorch安装
# 基础CPU版本
pip3 install torch torchaudio
# GPU版本(需根据CUDA版本匹配)
# pip3 install torch torchaudio --index-url https://download.pytorch.org/whl/cu118
Docker容器化部署
对于企业级应用或多环境一致性要求,推荐使用Docker部署:
安装Docker
# Ubuntu系统
curl -fsSL https://test.docker.com -o test-docker.sh
sudo sh test-docker.sh
# CentOS系统
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
运行FunASR容器
# 拉取CPU镜像
sudo docker pull registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.4.1
# 启动容器
sudo docker run -itd --name funasr -v ./data:/workspace/data registry.cn-hangzhou.aliyuncs.com/funasr_repo/funasr:funasr-runtime-sdk-cpu-0.4.1 /bin/bash
详细Docker部署文档:docs/installation/docker_zh.md
验证安装
安装完成后,可通过以下命令验证:
# 基础语音识别测试
from funasr import AutoModel
model = AutoModel(model="paraformer-zh", model_revision="v2.0.4")
res = model.generate(input="https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav")
print(res)
常见问题解决
M1/M2芯片Mac用户架构错误
pip uninstall cffi pycparser
ARCHFLAGS="-arch arm64" pip install cffi pycparser --compile --no-cache-dir
模型下载问题
推荐安装ModelScope获取预训练模型:
pip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple
模型仓库列表:model_zoo/modelscope_models_zh.md
下一步学习
- 快速启动指南:runtime/quick_start_zh.md
- 离线SDK开发:docs/SDK_advanced_guide_offline_zh.md
- 模型训练教程:examples/aishell/paraformer/
点赞收藏本文,关注获取更多FunASR实战教程!下期将带来"实时语音转写系统搭建",敬请期待。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考





