lenML / ChatTTS-Forge

🍦 ChatTTS-Forge is a project developed around TTS generation model, implementing an API Server and a Gradio-based WebUI.
https://huggingface.co/spaces/lenML/ChatTTS-Forge
GNU Affero General Public License v3.0
480 stars 60 forks source link

Mac M1 下 sndfile 无法找到 #52

Open WangLaoShi opened 4 weeks ago

WangLaoShi commented 4 weeks ago

阅读 README.md 和 dependencies.md

检索 issue 和 discussion

检查 Forge 版本

你的issues

错误如下:

/Users/laoshi/PycharmProjects/ChatTTS-Forge/.venv/lib/python3.9/site-packages/pydub/utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
Traceback (most recent call last):
  File "/Users/laoshi/PycharmProjects/ChatTTS-Forge/.venv/lib/python3.9/site-packages/soundfile.py", line 267, in <module>
    _snd = _ffi.dlopen('sndfile')
  File "/Users/laoshi/PycharmProjects/ChatTTS-Forge/.venv/lib/python3.9/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Users/laoshi/PycharmProjects/ChatTTS-Forge/.venv/lib/python3.9/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/Users/laoshi/PycharmProjects/ChatTTS-Forge/.venv/lib/python3.9/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'sndfile'

解决方案:

按照 dependencies.md 中的步骤,无法实现。

可以参考https://github.com/bastibe/python-soundfile/ 实现。

WangLaoShi commented 4 weeks ago

我在代码中是这么实现的:

modules/api/impl/tts_api.py

try:
    # OSError: cannot load library '/*****_soundfile_data/libsndfile.dylib'
    import soundfile as sf
except:
    import os
    import platform

    # 获取当前系统名称
    system = platform.system()

    if system == 'Darwin':
        # 获取当前的DYLD_LIBRARY_PATH
        current_dyld_library_path = os.environ.get('DYLD_LIBRARY_PATH', '')

        # 要追加的路径
        new_dyld_library_path = '/opt/homebrew/lib'

        # 设置新的DYLD_LIBRARY_PATH,如果已存在则追加,否则设置为新值
        if current_dyld_library_path:
            os.environ['DYLD_LIBRARY_PATH'] = f"{new_dyld_library_path}:{current_dyld_library_path}"
        else:
            os.environ['DYLD_LIBRARY_PATH'] = new_dyld_library_path

        # 输出验证
        print(os.environ['DYLD_LIBRARY_PATH'])

        import soundfile as sf