2noise / ChatTTS

A generative speech model for daily dialogue.
https://2noise.com
Other
27.81k stars 3.02k forks source link

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

Closed PSSUN closed 1 month ago

PSSUN commented 1 month ago

OS: windows 11

Error message:

---------------------------------------------------------------------------
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.

I have installed soundfile and pysoundfile, but still error.

jianchang512 commented 1 month ago

Download ffmpeg and add Path var

or edit the code

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

to

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

Flame1117 commented 1 month ago

已解决! 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

jianchang512 commented 1 month ago

重新 git pull

test.py 有点错误,改用 soundfile

jianchang512 commented 1 month ago

2楼不是说了吗,不要使用 torchaudio ,删掉相关代码,使用 soundfile

pip install soundfile

szhdanxiaoxi commented 1 month ago

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会报这个错

libukai commented 1 month ago

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

代码需要修正

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

推荐一下我自己 fork 的版本,ChatTTS-Control

web-ui

Yinshuofeng commented 1 month ago

感谢楼上 可以了!

chenmonster commented 1 month ago

2楼不是说了吗,不要使用 torchaudio ,删掉相关代码,使用 soundfile

pip install soundfile

我用你说的第一种方法运行没问题,就是需要安装 ffmpeg 软件

apt update
apt install ffmpeg -y
ffmpeg -version
njhouse365 commented 1 month ago

还是soundflie可靠