CosyVoice2在Windows系统上本地部署的详细步骤:
-
下载源码并初始化:
- 确保你的设备上安装了Git。
- 打开命令提示符(cmd),执行以下命令来克隆仓库:
git clone --recursive https://github.com/FunAudioLLM/CosyVoice.git cd CosyVoice git submodule update --init --recursive
-
安装Anaconda:
- 访问Anaconda官网下载最新版,并按照指示安装。
-
创建并激活虚拟环境:
- 使用Conda创建一个Python 3.8的虚拟环境(或者根据需要选择其他版本):
conda create -n cosyvoice python=3.10 conda activate cosyvoice
- 使用Conda创建一个Python 3.8的虚拟环境(或者根据需要选择其他版本):
-
安装pynini模块:
- 在激活的虚拟环境中,通过Conda安装pynini:
conda install -y -c conda-forge pynini==2.1.5
- 在激活的虚拟环境中,通过Conda安装pynini:
-
依赖安装:
-
如果您不使用显卡(GPU)您只需要确保您的 Python 环境正确安装,并使用
onnxruntime
而不是onnxruntime-gpu
来运行 CosyVoice2 -
首先,使用文本编辑器打开项目目录下的
requirements.txt
文件,然后要修改
requirements.txt
以使用 CPU 版本 的onnxruntime
,您需要:- 删除 GPU 相关的
onnxruntime-gpu
和tensorrt
依赖 - 保留或修改
onnxruntime
为 CPU 版本 - 删除额外的 CUDA 相关索引 URL
- 修改后的
requirements.txt
(CPU 版本)如下:conformer==0.3.2 diffusers==0.29.0 gdown==5.1.0 gradio==5.4.0 grpcio==1.57.0 grpcio-tools==1.57.0 hydra-core==1.3.2 HyperPyYAML==1.2.2 inflect==7.3.1 librosa==0.10.2 lightning==2.2.4 matplotlib==3.7.5 modelscope==1.15.0 networkx==3.1 omegaconf==2.3.0 onnx==1.16.0 onnxruntime==1.18.0 # 使用 CPU 版本,删除 GPU 版本 openai-whisper==20231117 protobuf==4.25 pydantic==2.7.0 pyworld==0.3.4 rich==13.7.1 soundfile==0.12.1 tensorboard==2.14.0 torch==2.3.1 torchaudio==2.3.1 transformers==4.40.1 uvicorn==0.30.0 wget==3.2 fastapi==0.115.6 fastapi-cli==0.0.4 WeTextProcessing==1.0.3
删除的内容
--extra-index-url https://download.pytorch.org/whl/cu121
--extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/
onnxruntime-gpu==1.18.0; sys_platform == 'linux'
tensorrt-cu12==10.0.1; sys_platform == 'linux'
tensorrt-cu12-bindings==10.0.1; sys_platform == 'linux'
tensorrt-cu12-libs==10.0.1; sys_platform == 'linux'
deepspeed==0.14.2; sys_platform == 'linux'
(DeepSpeed 主要用于 GPU 加速,CPU 下可移除)
安装方法
- 删除 GPU 相关的
-
安装项目所需的库,可以使用国内镜像加快下载速度:
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
-
-
下载模型文件:
- 将预训练模型下载到
pretrained_models
目录下:git clone https://www.modelscope.cn/iic/CosyVoice2-0.5B.git pretrained_models/CosyVoice2-0.5B
- 将预训练模型下载到
-
启动WebUI:
- 运行webui.py脚本来启动服务:
python webui.py --port 50000 --model_dir pretrained_models/CosyVoice2-0.5B
- 完成后可以通过访问
http://127.0.0.1:50000
来查看界面。
- 运行webui.py脚本来启动服务:
-
解决可能遇到的问题:
- 如果缺少ffmpeg,请自行搜索安装方法,例如可以在B站找到教程。
- 如果出现其他错误,比如
ModuleNotFoundError
,请检查是否有遗漏的子模块或依赖项,并确保所有必要的文件都已正确下载和配置。
使用: