[2noise/ChatTTS]运行时错误:找不到适当的后端来处理 uri output1.wav 和格式 wav。

2024-06-06 675 views
7

操作系统:Windows 11

错误信息:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[17], line 1
----> 1 torchaudio.save("output1.wav", torch.from_numpy(wavs[0]), 24000, format='wav')

File F:\conda\Lib\site-packages\torchaudio\_backend\utils.py:311, in get_save_func.<locals>.save(uri, src, sample_rate, channels_first, format, encoding, bits_per_sample, buffer_size, backend, compression)
    223 def save(
    224     uri: Union[BinaryIO, str, os.PathLike],
    225     src: torch.Tensor,
   (...)
    233     compression: Optional[Union[CodecConfig, float, int]] = None,
    234 ):
    235     """Save audio data to file.
    236 
    237     Note:
   (...)
    309 
    310     """
--> 311     backend = dispatcher(uri, format, backend)
    312     return backend.save(
    313         uri, src, sample_rate, channels_first, format, encoding, bits_per_sample, buffer_size, compression
    314     )

File F:\conda\Lib\site-packages\torchaudio\_backend\utils.py:221, in get_save_func.<locals>.dispatcher(uri, format, backend_name)
    219     if backend.can_encode(uri, format):
    220         return backend
--> 221 raise RuntimeError(f"Couldn't find appropriate backend to handle uri {uri} and format {format}.")

RuntimeError: Couldn't find appropriate backend to handle uri output1.wav and format wav.

我已经安装了 soundfilepysoundfile,但仍然错误。

回答

2

下载ffmpeg并添加Path var

或编辑代码

torchaudio.save("output1.wav", torch.from_numpy(wavs[0]), 24000, format='wav')

soundfile.write("output1.wav", wavs[0], 24000)

7

已解决! OS: windows 11

在 Anaconda 环境中安装指定的 Python 包

创建并激活新的 Conda 环境 conda create -n myenv python=3.9 conda activate myenv

使用 conda 安装 ipython 和 tqdm conda install ipython tqdm

使用 pip 安装其余的包 pip install omegaconf==2.3.0 torch==2.1.0 einops vector_quantize_pytorch transformers==4.41.1 vocos

pip install soudfile

test.py

import soundfile import ChatTTS

chat = ChatTTS.Chat() chat.load_models(source='local', local_path='D:\zhanxy\ChatTTS\ChatTTS\model2\chatTTS') texts = ["由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。",]

wavs = chat.infer(texts, use_decoder=True) soundfile.write("output1.wav", wavs[0][0], 24000)

log

INFO:ChatTTS.core:Load from local: D:\zhanxy\ChatTTS\ChatTTS\model2\chatTTS WARNING:ChatTTS.utils.gpu_utils:No GPU found, use CPU instead INFO:ChatTTS.core:use cpu INFO:ChatTTS.core:vocos loaded. INFO:ChatTTS.core:dvae loaded. INFO:ChatTTS.core:gpt loaded. INFO:ChatTTS.core:decoder loaded. INFO:ChatTTS.core:tokenizer loaded. INFO:ChatTTS.core:All initialized. INFO:ChatTTS.core:All initialized. 11%|█ | 41/384 [00:02<00:22, 15.01it/s] 16%|█▌ | 325/2048 [00:16<01:27, 19.76it/s]

Process finished with exit code 0

9

重新 git pull

test.py 有点错误,改用声音文件

7

2楼没有说了吗,不要使用torchaudio,删掉相关代码,使用声音文件

pip 安装声音文件

9

WARNING:ChatTTS.utils.gpu_utils:No GPU found, use CPU instead INFO:ChatTTS.core:use cpu INFO:ChatTTS.core:vocos loaded. INFO:ChatTTS.core:dvae loaded. INFO:ChatTTS.core:gpt loaded. INFO:ChatTTS.core:decoder loaded. INFO:ChatTTS.core:tokenizer loaded. INFO:ChatTTS.core:All initialized. INFO:ChatTTS.core:All initialized. 3%|▎ | 12/384 [00:00<00:21, 17.11it/s] 4%|▍ | 83/2048 [00:03<01:15, 25.93it/s] Traceback (most recent call last): File "E:\causal\ml\venv\ChatTTS-main\chattts.py", line 17, in soundfile.write("E:/causal/ml/venv/ChatTTS-main/output/output1.wav", wavs[0], 24000) File "E:\causal\ml\venv\Lib\site-packages\soundfile.py", line 343, in write with SoundFile(file, 'w', samplerate, channels, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\causal\ml\venv\Lib\site-packages\soundfile.py", line 658, in init self._file = self._open(file, mode_int, closefd) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\causal\ml\venv\Lib\site-packages\soundfile.py", line 1216, in _open raise LibsndfileError(err, prefix="Error opening {0!r}: ".format(self.name)) soundfile.LibsndfileError: Error opening 'E:/causal/ml/venv/ChatTTS-main/output/output1.wav': Format not recognised.

换成soundfile会报这个错

2

soundfile.write("output1.wav", wavs[0], 24000)

代码需要修改

soundfile.write("output1.wav", wavs[0][0], 24000)