Published on

Style-Bert-VITS2をMacOSで動かしてみた

Authors

Style-Bert-VITS2というOSSをMacOSで試そうとしたところ、公式ではWindows前提で手順通りインストールすることができなかった。

試行錯誤することでWebUIの起動に成功したため、具体的な方法を紹介する。

結論

躓いた箇所はライブラリの依存関係や必要なライブラリが足りないところにあったため、主にrequirementsの調整をすることで起動させることができた。 また、詳細は後述するがuv pip install "torch<2.4" "torchaudio<2.4" --index-url https://download.pytorch.org/whl/cu118をスキップするとエラーを回避できた。

GitHubに調整したrequirementsを置いている。

リポジトリ

litagin02/Style-Bert-VITS2をフォークしたリポジトリであるため、今回追加したMacOS用のrequirements-macos.txtからライブラリをインストールすると

起動成功までの流れ

uv pip install "torch<2.4" "torchaudio<2.4" --index-url https://download.pytorch.org/whl/cu118を実行すると以下のエラーが出力された。

Using Python 3.10.18 environment at: env
  × No solution found when resolving dependencies:
  ╰─▶ Because only the following versions of torch are available:
          torch==0.1
          torch==0.1.6.post17
          torch==0.1.6.post20
          torch==0.1.6.post22
          torch==0.1.7.post2
          torch==0.1.8.post1
          torch==0.1.9.post1
          torch==0.1.9.post2
          torch==0.1.10.post1
          torch==0.1.11.post4
          torch==0.1.11.post5
          torch==0.1.12.post1
          torch==0.1.12.post2
          torch==0.2.0.post1
          torch==0.2.0.post2
          torch==0.2.0.post3
          torch==0.3.0
          torch==0.3.0.post2
          torch==0.3.0.post3
          torch==0.3.0.post4
          torch==0.3.1
          torch==0.4.0
          torch==0.4.1
          torch==1.11.0
          torch==1.12.0
          torch==1.12.1
          torch==1.13.0
          torch==1.13.1
          torch==2.0.0
          torch==2.0.0+cu118
          torch==2.0.1
          torch==2.0.1+cu118
          torch==2.1.0+cu118
          torch==2.1.1+cu118
          torch==2.1.2+cu118
          torch==2.2.0+cu118
          torch==2.2.1+cu118
          torch==2.2.2+cu118
          torch==2.3.0+cu118
          torch==2.3.1+cu118
          torch>2.4
      and torch<=0.4.1 has no wheels with a matching Python ABI tag (e.g., `cp310`), we can conclude that torch<=0.4.1 cannot be used.
      And because torch>=1.11.0,<=2.3.1+cu118 has no wheels with a matching platform tag (e.g., `macosx_26_0_arm64`) and you require torch<2.4, we can
      conclude that your requirements are unsatisfiable.

      hint: You require CPython 3.10 (`cp310`), but we only found wheels for `torch` (v0.4.1) with the following Python ABI tags: `cp35m`, `cp36m`, `cp37m`

      hint: Wheels are available for `torch` (v2.3.1+cu118) on the following platforms: `linux_x86_64`, `win_amd64`

TorchをCUDAで使用するためのインストールであるが、Apple Siliconでは使えないようなのでスキップする。 Apple SiliconでGPUを利用するには、CUDAでなくMetalというものを使う必要があるらしいが、TorchはApple Silicon向けにMetalを使うための機能が備わっているいるため通常のtorchインストールで使えるようになる。ゆえにスキップで問題ない。 torchとtorchaudioはrequirements.txtに追加されているので、次手順のuv pip install -r requirements.txtする。

今度は以下のエラーが出力される。

Using Python 3.10.18 environment at: env
⠙ gradio==5.49.1
  × Failed to build av==10.0.0
  ├─▶ The build backend returned an error
  ╰─▶ Call to setuptools.build_meta:__legacy__.build_wheel failed (exit status: 1)

      [stdout]
      Compiling av/logging.pyx because it changed.
      [1/1] Cythonizing av/logging.pyx

      [stderr]
      performance hint: av/logging.pyx:232:0: Exception check on 'log_callback' will always require the GIL to be acquired.
      Possible solutions:
        1. Declare 'log_callback' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'log_callback' to allow an error code to be returned.

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
      cdef const char *log_context_name(void *ptr) nogil:
          cdef log_context *obj = <log_context*>ptr
          return obj.name

      cdef lib.AVClass log_class
      log_class.item_name = log_context_name
                            ^
      ------------------------------------------------------------
      av/logging.pyx:216:22: Cannot assign type 'const char *(void *) except? NULL nogil' to 'const char *(*)(void *) noexcept nogil'. Exception values are
      incompatible. Suggest adding 'noexcept' to the type of 'log_context_name'.

      Error compiling Cython file:
      ------------------------------------------------------------
      ...

      # Start the magic!
      # We allow the user to fully disable the logging system as it will not play
      # nicely with subinterpreters due to FFmpeg-created threads.
      if os.environ.get('PYAV_LOGGING') != 'off':
          lib.av_log_set_callback(log_callback)
                                  ^
      ------------------------------------------------------------
      av/logging.pyx:351:28: Cannot assign type 'void (void *, int, const char *, va_list) except * nogil' to 'av_log_callback' (alias of 'void (*)(void *,
      int, const char *, va_list) noexcept nogil'). Exception values are incompatible. Suggest adding 'noexcept' to the type of 'log_callback'.
      Traceback (most recent call last):
        File "<string>", line 14, in <module>
        File "/Users/xxxx/.cache/uv/builds-v0/.tmp2k8S8M/lib/python3.10/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "/Users/xxxx/.cache/uv/builds-v0/.tmp2k8S8M/lib/python3.10/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
          self.run_setup()
        File "/Users/xxxx/.cache/uv/builds-v0/.tmp2k8S8M/lib/python3.10/site-packages/setuptools/build_meta.py", line 512, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/Users/xxxx/.cache/uv/builds-v0/.tmp2k8S8M/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup
          exec(code, locals())
        File "<string>", line 157, in <module>
        File "/Users/xxxx/.cache/uv/builds-v0/.tmp2k8S8M/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1153, in cythonize
          cythonize_one(*args)
        File "/Users/xxxx/.cache/uv/builds-v0/.tmp2k8S8M/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1297, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: av/logging.pyx

      hint: This usually indicates a problem with the package or the build environment.
  help: av (v10.0.0) was included because faster-whisper (v0.10.1) depends on av>=10.dev0, <11.dev0

av==10.0.0がCython3系のビルドで失敗しているので、avライブラリのアップデートをする必要がある。avはfaster-whisperをアップデートすると自動的にバージョンが引き上がるので、faster-whisperのバージョン指定を外してインストールしてみる。

すると、エラーは解決してインストールが無事に終了する。そのまま、手順通りにpython initialize.pyを実行して完了後python app.pyを実行する。

ここで別のエラーが発生する。

/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/librosa/util/files.py:10: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import resource_filename
Traceback (most recent call last):
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 2317, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 2347, in _get_module
    raise e
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 2345, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/Users/xxxx/.local/share/uv/python/cpython-3.10.18-macos-aarch64-none/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_deberta_v2.py", line 25, in <module>
    from ...modeling_layers import GradientCheckpointingLayer
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/modeling_layers.py", line 28, in <module>
    from .processing_utils import Unpack
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/processing_utils.py", line 34, in <module>
    from .audio_utils import AudioInput, load_audio
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/audio_utils.py", line 52, in <module>
    import soxr
ModuleNotFoundError: No module named 'soxr'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/xxxx/Style-Bert-VITS2/server_editor.py", line 44, in <module>
    from style_bert_vits2.nlp import bert_models, onnx_bert_models
  File "/Users/xxxx/Style-Bert-VITS2/style_bert_vits2/nlp/bert_models.py", line 17, in <module>
    from transformers import (
  File "/Users/xxxx/Style-Bert-VITS2/env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 2320, in __getattr__
    raise ModuleNotFoundError(
ModuleNotFoundError: Could not import module 'DebertaV2Model'. Are this object's requirements defined correctly?

audio_utilsの要求するsoxrライブラリがないため、requirements.txtに追加してインストールするとやっとエラーが出ずにインストールできる。

WebUIの起動をするために、python app.pyを実行すると問題なく立ち上がるが、音声合成を実行するとエラーとなる。ログを見てみると以下のエラーが出力されている。

Value error: Due to a serious vulnerability issue in `torch.load`, even with `weights_only=True`, we now require users to upgrade torch to at least v2.6 in order to use the function. This version restriction does not apply when loading files with safetensors.
See the vulnerability report here https://nvd.nist.gov/vuln/detail/CVE-2025-32434

脆弱性の影響で、torchのバージョンを少なくとも2.6には上げるよう指示が出ているので、requirements.txtのtorchとtorchaudioのバージョン指定を外してアップグレードしてみる。

そうすると、音声合成も無事に実行することができるようになった。