[2noise/ChatTTS]torchaudio.save报错

2024-08-19 809 views
1

最新的代码中使用torchaudio.save(audioFile, torch.from_numpy(wavs[0]), 24000)时,在实体机上运行正常,但是在docker中运行的时候就会报错: File "/data/ChatTTS/examples/web/infura.py", line 82, in customAudio torchaudio.save(audioFile, torch.from_numpy(wavs[0]), 24000) File "/root/anaconda3/lib/python3.10/site-packages/torchaudio/_backend/utils.py", line 315, in save backend = dispatcher(uri, format, backend) File "/root/anaconda3/lib/python3.10/site-packages/torchaudio/_backend/utils.py", line 223, in dispatcher raise RuntimeError(f"Couldn't find appropriate backend to handle uri {uri} and format {format}.")

回答

1

For Linux: pip install sox Windows & Mac: pip install soundfile

4

多谢回答,但是安装了sox,问题依旧!

3

可以用tools/audio下相关函数保存,用法详见examples/webexamples/cmd

5

谢谢回复,但是使用了cmd中的类似代码后也是报错,只是报错的原因是:

File "/data/ChatTTS/examples/web/infura.py", line 56, in saveMp3 data = pcm_arr_to_mp3_view(wav) File "/data/ChatTTS/ttstools/audio/pcm.py", line 16, in pcm_arr_to_mp3_view wf.writeframes(float_to_int16(wav)) File "/root/anaconda3/lib/python3.10/site-packages/numba/core/dispatcher.py", line 423, in _compile_for_args error_rewrite(e, 'typing') File "/root/anaconda3/lib/python3.10/site-packages/numba/core/dispatcher.py", line 364, in error_rewrite raise e.with_traceback(None) numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) Unknown attribute 'max' of type float32

1

打印一下wav,看看是什么。pcm_arr_to_mp3_view接受的参数是一维numpy数组,可通过wavs[0]获得。

6

Make sure that the dependency libraries required for audio processing are installed in the container,print it first

import ChatTTS
import torch
import torchaudio

print("[audio list]",str(torchaudio.list_audio_backends()))
# when result is  [] ,I think so you must install libsox-dev sox 

just like this and try again

apt-get update && apt-get install -y libsox-dev sox

# ['sox', 'soundfile']