[2noise/ChatTTS]运行examples/api下的实例时,提示ModuleNotFoundError: No module named 'tools.audio'

2025-11-10 309 views
5

按照exaplmes/api/readme操作,操作步骤

1、clone git代码

2、安装依赖 进入Chattts目录,执行命令 pip install -r examples/api/requirements.txt

3、启动服务 fastapi dev examples/api/main.py --host 0.0.0.0 --port 8000

控制台报错: ModuleNotFoundError: No module named 'tools.audio'

感觉错误原因是tools目录下的包并没有包含在ChatTTS的安装文件中,所有找不到。这个问题如何解决?

回答

8

应该是你启动方式的问题。examples/web/webui.py也引用了tools,可以尝试运行一下。

0

pip uninstall tools

4

控制台输出:

Traceback (most recent call last): File "/root/ctts/examples/web/webui.py", line 13, in from funcs import * File "/root/ctts/examples/web/funcs.py", line 7, in from tools.audio import float_to_int16, has_ffmpeg_installed, load_audio ModuleNotFoundError: No module named 'tools.audio'

尝试 pip uninstall tools & pip install tools ,出同样的提示,未能解决问题。

目前用Jianchang512的ChatTTS-ui覆盖并装入ffmpeg后,用其根目录的app.py启动webui,但这不是长久之计。

2

控制台输出:

回溯(最近一次调用最后一次): 文件“/root/ctts/examples/web/webui.py”,第 13 行,来自 funcs 导入 * 文件“/root/ctts/examples/web/funcs.py”,第 7 行,来自 tools.audio 导入 float_to_int16、has_ffmpeg_installed、load_audio ModuleNotFoundError:没有名为“tools.audio”的模块

尝试 pip uninstall tools 和 pip install tools ,出现同样的提示,未能解决问题。

目前用Jianchang512的ChatTTS-ui覆盖并写入ffmpeg后,用其根目录的app.py启动webui,不过不是长久之计。

想问一下具体如何操作的

3

控制台输出: 回溯(最近一次调用最后一次): 文件“/root/ctts/examples/web/webui.py”,第 13 行,来自 funcs 导入 * 文件“/root/ctts/examples/web/funcs.py”,第 7 行,来自 tools.audio 导入 float_to_int16、has_ffmpeg_installed、load_audio ModuleNotFoundError:没有名为“tools.audio”的模块 尝试 pip uninstall tools 和 pip install tools ,出现同样的提示,未能解决问题。 目前用Jianchang512的ChatTTS-ui覆盖并写入ffmpeg后,用其根目录的app.py启动webui,不过不是长久之计。

想问一下具体如何操作的

原本我单独部署Chat-TTS的时候就出现了这个问题, 后来的起因我要部署这个利用Ollama进行语音交互的Git,https://github.com/hkgood/Ollama_ChatTTS 于是发现Chat-TTS在被覆盖之后,居然神奇的工作了, 所以朋友你可以复现一下它上面的步骤,应该是可以的。

另外,我操作的环境在Windows下。

7

没有办法吗?;)

import ChatTTS
import torch
import torchaudio
from typing import Optional
from tools.audio import float_to_int16, load_audio

用“tools.audio” 的时候还有这个问题: No module named 'tools.audio'

4

没有办法吗?;)

import ChatTTS
import torch
import torchaudio
from typing import Optional
from tools.audio import float_to_int16, load_audio

用“tools.audio” 的时候还有这个问题: No module named 'tools.audio'

Comparing code within funcs.py and its references, seems that "tools.audio" it's not a module which could be installed from pypi or somewhere else, however, it's definitely a tools package from ChatTTS root folder. So if we got "No module named 'tools.audio' message, it might be caused by Python couldn't read back from ChatTTS' root folder which containing /tools/audio/av.py, this one defines how "float_to_init16" and "load_audio" working.

So, just copy "ChatTTS" and "tools" folder into examples/web , problem solved.

Another way to fix:

add lines:

import sys sys.path.append("..") sys.path.append("../..")

into funcs.py after " import gradio as gr ". have fun :)