消除AttributeError: module ‘ttsfrd‘ has no attribute ‘TtsFrontendEngine‘报错输出的记录
#工作记录
尝试消除
消除“模块ttsfrd
没有属性ttsfrontendengine
”的错误的记录
报错摘录:
Traceback (most recent call last):
File "F:\PythonProjects\CosyVoice\webui.py", line 188, in <module>
cosyvoice = CosyVoice(args.model_dir)
File "F:\PythonProjects\CosyVoice\cosyvoice\cli\cosyvoice.py", line 41, in __init__
self.frontend = CosyVoiceFrontEnd(configs['get_tokenizer'],
File "F:\PythonProjects\CosyVoice\cosyvoice\cli\frontend.py", line 65, in __init__
self.frd = ttsfrd.TtsFrontendEngine()
AttributeError: module 'ttsfrd' has no attribute 'TtsFrontendEngine'
找到代码部分发现运行时强制使用 ttsfrd ,但是试了多种方法还是不管用,于是在代码中设置成禁用了:
# use_ttsfrd = Trueuse_ttsfrd = False
禁用后没有再输出报错信息。查阅了一下,禁用 ttsfrd ,项目会调用WeTextProcessing来代用。
尝试修复
其他修复方案可尝试:
pip install --upgrade ttsfrd
pip install "modelscope[audio]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
模块ttsfrd
没有属性ttsfrontendengine
的错误通常发生在代码逻辑中试图访问ttsfrd
模块中不存在的属性或方法时。
这可能是由于安装不正确、版本不匹配,或者仅仅是拼写错误。
示例
import ttsfrd
ttsfrd.ttsfrontendengine() # AttributeError: 模块 'ttsfrd' 没有属性 'ttsfrontendengine'
常见原因和解决方案
-
检查拼写错误 确保我们尝试访问的属性或方法名中没有拼写错误。
示例
import ttsfrd ttsfrd.ttsfrontendengine() # 错误写法
解决方法: 从模块的文档中验证正确的属性或方法名
import ttsfrd ttsfrd.correct_method_name() # 正确用法
-
验证安装 确保
ttsfrd
模块已正确安装。我们可以使用pip
重新安装它。示例
pip install ttsfrd -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
-
检查模块版本 确保我们使用的
ttsfrd
模块版本包含ttsfrontendengine
属性。示例
pip show ttsfrd
查看版本信息,并在必要时更新
pip install --upgrade ttsfrd -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
-
使用 ModelScope 音频依赖 如果
ttsfrd
是 ModelScope 的一部分,我们可以安装所有音频依赖以确保兼容性。示例
pip install "modelscope[audio]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html