PaddlePaddle / PaddleSpeech

Easy-to-use Speech Toolkit including Self-Supervised Learning model, SOTA/Streaming ASR with punctuation, Streaming TTS with text frontend, Speaker Verification System, End-to-End Speech Translation and Keyword Spotting. Won NAACL2022 Best Demo Award.
https://paddlespeech.readthedocs.io
Apache License 2.0
10.99k stars 1.83k forks source link

训练出来的模型在linux部署时出现了错误 #2724

Closed GuangHeLiZi closed 1 year ago

GuangHeLiZi commented 1 year ago

我按照 https://aistudio.baidu.com/aistudio/projectdetail/5003396 训练出了名为ce.zip的模型 并根据 https://zhuanlan.zhihu.com/p/587765776 的教程在linux上部署了飞桨环境,但每次都会出现意想不到的错误。 如下:

_python3 test.py Traceback (most recent call last): File "/usr/local/python3/lib/python3.9/site-packages/soundfile.py", line 151, in raise OSError('sndfile library not found') OSError: sndfile library not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/python3/lib/python3.9/site-packages/soundfile.py", line 178, in _snd = _ffi.dlopen(_os.path.join(_path, '_soundfile_data', _packaged_libname)) OSError: cannot load library '/usr/local/python3/lib/python3.9/site-packages/_soundfile_data/libsndfile.so': /usr/local/python3/lib/python3.9/site-packages/_soundfile_data/libsndfile.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/PaddleSpeech/test.py", line 2, in import soundfile as sf File "/usr/local/python3/lib/python3.9/site-packages/soundfile.py", line 189, in _snd = _ffi.dlopen(libname) OSError: cannot load library 'libsndfile.so': libsndfile.so: cannot open shared object file: No such file or directory

test.py 里的内容: from pathlib import Path import soundfile as sf import os from paddlespeech.t2s.exps.syn_utils import get_am_output from paddlespeech.t2s.exps.syn_utils import get_frontend from paddlespeech.t2s.exps.syn_utils import get_predictor from paddlespeech.t2s.exps.syn_utils import get_voc_output

在其他环境中,记得修改下面这两个变量的路径

am_inference_dir = "/home/ce" voc_inference_dir = "/home/pwgan_aishell3_static_1.1.0" # 这里以 pwgan_aishell3 为例子

音频生成的路径,修改成你音频想要保存的路径

wav_output_dir = "/home"

选择设备[gpu / cpu],这里以GPU为例子,

device = "cpu"

想要生成的文本和对应文件名

text_dict = { "1": "我很快失去了下棋的斗志", "2": "我认为跑步给我的身体带来了健康。", }

frontend

frontend = get_frontend( lang="mix", phones_dict=os.path.join(am_inference_dir, "phone_id_map.txt"), tones_dict=None )

am_predictor

am_predictor = get_predictor( model_dir=am_inference_dir, model_file="fastspeech2_mix" + ".pdmodel", params_file="fastspeech2_mix" + ".pdiparams", device=device)

voc_predictor

voc_predictor = get_predictor( model_dir=voc_inference_dir, model_file="pwgan_aishell3" + ".pdmodel", # 这里以 pwgan_aishell3 为例子,其它模型记得修改此处模型名称 params_file="pwgan_aishell3" + ".pdiparams", device=device)

output_dir = Path(wav_output_dir) output_dir.mkdir(parents=True, exist_ok=True)

sentences = list(text_dict.items())

merge_sentences = True fs = 24000 for utt_id, sentence in sentences: am_output_data = get_am_output( input=sentence, am_predictor=am_predictor, am="fastspeech2_mix", frontend=frontend, lang="mix", merge_sentences=merge_sentences, speaker_dict=os.path.join(am_inference_dir, "phone_id_map.txt"), spk_id=0, ) wav = get_voc_output( voc_predictor=voc_predictor, input=am_output_data)

保存文件

sf.write(output_dir / (utt_id + ".wav"), wav, samplerate=fs)

我想知道我大概在那一步出了问题,因为我不管怎么去修改重新安装python环境或者在docker中运行,都会报各种错误。非常感谢。

我大致的想法是把训练的模型部署在linux服务器中,通过http接口的形式去让项目调用。

yt605155624 commented 1 year ago

这是你的报错

OSError: sndfile library not found

解决办法

sudo apt-get install libsndfile1