源代码本地安装funasr
源码部署FUNASR
1. 下载源代码
github:
GitHub - modelscope/FunASR: A Fundamental End-to-End Speech Recognition Toolkit and Open Source SOTA Pretrained Models, Supporting Speech Recognition, Voice Activity Detection, Text Post-processing etc.
gitee:https://gitee.com/mirrors/funasr/tree/main/
2. 源码安装
安装torch torchaudio(CPU版)
pip install torch==2.2.2+cpu torchaudio==2.2.2# 下载pytorch
https://pytorch.org/get-started/previous-versions/
# 命令
conda install pytorch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 cpuonly -c pytorch
源码安装
cd funasr/pip3 install -e ./
运行实例:
# 识别示例语音
funasr ++model=paraformer-en ++vad_model="fsmn-vad" ++punc_model="ct-punc" ++input="./asr_example_en.wav" +disable_update=True
3. 报错` File “/home/pywcc/miniconda3/envs/python3.10/lib/python3.10/ctypes/init.py”, line 374, in init
self._handle = _dlopen(self._name, mode)
OSError: libtorch_cuda.so: cannot open shared object file: No such file or directory`
# 下载示例语音,指定
wget https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_en.wav
4. 报错`File “/home/pywcc/funasr-main/funasr/models/fsmn_vad_streaming/model.py”, line 690, in inferenceaudio_sample = torch.cat((cache[“prev_samples”], audio_sample_list[0]))
TypeError: expected Tensor as element 1 in argument 0, but got str`
排查步骤
- 检查按文件路径是否带“”,且是否源文件名称一致
TypeError: expected Tensor as element 1 in argument 0, but got str · Issue #1327 · modelscope/FunASR (github.com)
如语音文件名字是asr_example_en.wav
而不是asr_example-en.wav
报错:A module that was compiled using NumPy 1.x cannot be run in NumPy 2.2.6 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2.Traceback (most recent call last): File "/home/pywcc/miniconda3/envs/python3.10/bin/funasr", line 33, in <module> sys.exit(load_entry_point('funasr', 'console_scripts', 'funasr')()) File "/home/pywcc/miniconda3/envs/python3.10/lib/python3.10/site-packages/torch/nn/modules/transformer.py", line 20, in <module> device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'), /home/pywcc/miniconda3/envs/python3.10/lib/python3.10/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at /opt/conda/conda-bld/pytorch_1711403233856/work/torch/csrc/utils/tensor_numpy.cpp:84.)
或者
File "/home/pywcc/funasr-main/funasr/frontends/wav_frontend.py", line 269, in apply_cmvn means = np.tile(cmvn[0:1, :dim], (frame, 1)) File "/home/pywcc/miniconda3/envs/python3.10/lib/python3.10/site-packages/numpy/lib/_shape_base_impl.py", line 1276, in tile c = _nx.array(A, copy=None, subok=True, ndmin=d) ValueError: object __array__ method not producing an array
解决办法:
-
安装
pip install numpy==1.24.0
-
重新源码安装funasr