LoginSignup
0
0

More than 1 year has passed since last update.

RHEL系Linux(Oracle Linux)でSpleeterをセットアップしてみる

Posted at

はじめに

minicondaを使わないRHEL系LinuxでのSpleeterセットアップの情報が全く見つからず、やってみましたが思いの外難しかったので実施したことをメモしておきます。

これをやってみようと思った背景は、DAW(StudioOne)で録音した楽器のパート別音源に、録音のやり方が悪かったのか別パートの音が混じってしまっていたため、これをなんとか分割できないか調べているうちにSpleeterにたどり着いた、というところから始まっています。
また、セットアップのために極力ローカルPCを汚したくなく、OCIの無料のAlwaysFreeインスタンスでやってみることにしました。

環境

Oracle Cloud Infrastructure Always FreeのOracle Linuxで試しています。

OS: Oracle Linux 8.4
VM: VM.Standard.E2.1.Micro(Always Free対象)
Python: python3.6

Spleeterインストールまで

ffmpegというものが必要?

頑張って調べるとこのページにたどり着く。
以下コマンドでリポジトリ追加。

$ sudo yum install epel-release
$ sudo dnf install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
$ sudo dnf install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm

とりあえずインストールを試すがエラー。

$ sudo yum install ffmpeg ffmpeg-devel
RPM Fusion for EL 8 - Free - Updates                                                                                                                             182 kB/s | 290 kB     00:01    
エラー: 
 問題 1: conflicting requests
  - nothing provides libSDL2-2.0.so.0()(64bit) needed by ffmpeg-4.2.4-2.el8.x86_64
 問題 2: package ffmpeg-devel-4.2.4-2.el8.x86_64 requires libavdevice(x86-64) = 4.2.4-2.el8, but none of the providers can be installed
  - package ffmpeg-devel-4.2.4-2.el8.x86_64 requires libavdevice.so.58()(64bit), but none of the providers can be installed
  - conflicting requests
  - nothing provides libSDL2-2.0.so.0()(64bit) needed by libavdevice-4.2.4-2.el8.x86_64
(インストール不可のパッケージをスキップするには、'--skip-broken' を追加してみてください または、'--nobest' を追加して、最適候補のパッケージのみを使用しないでください)

これも必要っぽい。なんとかインストール成功。

$ sudo dnf install http://rpmfind.net/linux/epel/7/x86_64/Packages/s/SDL2-2.0.14-2.el7.x86_64.rpm
$ sudo yum install ffmpeg ffmpeg-devel

これで良いっぽい?

$ ffmpeg -version
ffmpeg version 4.2.4 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsrt --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

spleeterのインストール

とりあえず一回インストール試してみるも失敗?

$ sudo pip3 install spleeter
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting spleeter
  Downloading https://files.pythonhosted.org/packages/fb/2e/5d2cd3d0179d3f749d03eddf0172f1dbababbc371c1b5cbd7fc27d741070/spleeter-2.2.2-py3-none-any.whl (50kB)
    100% |████████████████████████████████| 51kB 6.6MB/s 
Collecting importlib-resources<5.0.0,>=4.1.1; python_version < "3.7" (from spleeter)
  Downloading https://files.pythonhosted.org/packages/e1/44/a4d7387e5207e66e567c04f87b652a9a174335043838ee7f85ef05f28945/importlib_resources-4.1.1-py3-none-any.whl
Collecting importlib-metadata<4.0.0,>=3.0.0; python_version < "3.8" (from spleeter)
  Downloading https://files.pythonhosted.org/packages/52/d0/bdb31463f2d9ca111e39b268518e9baa3542ef73ca449b711a7b4da69764/importlib_metadata-3.10.1-py3-none-any.whl
Collecting typer<0.4.0,>=0.3.2 (from spleeter)
  Downloading https://files.pythonhosted.org/packages/90/34/d138832f6945432c638f32137e6c79a3b682f06a63c488dcfaca6b166c64/typer-0.3.2-py3-none-any.whl
Collecting numpy<1.19.0,>=1.16.0 (from spleeter)
  Downloading https://files.pythonhosted.org/packages/b3/a9/b1bc4c935ed063766bce7d3e8c7b20bd52e515ff1c732b02caacf7918e5a/numpy-1.18.5-cp36-cp36m-manylinux1_x86_64.whl (20.1MB)
    100% |████████████████████████████████| 20.1MB 28kB/s 
Collecting httpx[http2]<0.17.0,>=0.16.1 (from spleeter)
  Downloading https://files.pythonhosted.org/packages/2d/c6/59aa4188e7eddb9e89ec67a51598ca6bfc09f1b38c9b45f7ee45af7a4df4/httpx-0.16.1-py3-none-any.whl (65kB)
    100% |████████████████████████████████| 71kB 6.3MB/s 
Collecting pandas==1.1.2 (from spleeter)
  Downloading https://files.pythonhosted.org/packages/1c/11/e1f53db0614f2721027aab297c8afd2eaf58d33d566441a97ea454541c5e/pandas-1.1.2-cp36-cp36m-manylinux1_x86_64.whl (10.5MB)
    100% |████████████████████████████████| 10.5MB 56kB/s 
Collecting tensorflow==2.3.0 (from spleeter)
  Could not find a version that satisfies the requirement tensorflow==2.3.0 (from spleeter) (from versions: 0.12.1, 1.0.0, 1.0.1, 1.1.0rc0, 1.1.0rc1, 1.1.0rc2, 1.1.0, 1.2.0rc0, 1.2.0rc1, 1.2.0rc2, 1.2.0, 1.2.1, 1.3.0rc0, 1.3.0rc1, 1.3.0rc2, 1.3.0, 1.4.0rc0, 1.4.0rc1, 1.4.0, 1.4.1, 1.5.0rc0, 1.5.0rc1, 1.5.0, 1.5.1, 1.6.0rc0, 1.6.0rc1, 1.6.0, 1.7.0rc0, 1.7.0rc1, 1.7.0, 1.7.1, 1.8.0rc0, 1.8.0rc1, 1.8.0, 1.9.0rc0, 1.9.0rc1, 1.9.0rc2, 1.9.0, 1.10.0rc0, 1.10.0rc1, 1.10.0, 1.10.1, 1.11.0rc0, 1.11.0rc1, 1.11.0rc2, 1.11.0, 1.12.0rc0, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.2, 1.12.3, 1.13.0rc0, 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 2.0.0a0, 2.0.0b0, 2.0.0b1)
No matching distribution found for tensorflow==2.3.0 (from spleeter)

pipのバージョンが古いとダメな場合があるようで。とりあえずバージョン上げてみる。

$ sudo pip3 install --upgrade pip
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/7c/02/9ab8b431aca1b46fcc1ac830a5870a28a12ba1abfa681904b1d2da876a86/pip-21.2.1-py3-none-any.whl (1.6MB)
    100% |████████████████████████████████| 1.6MB 299kB/s 
Installing collected packages: pip
Successfully installed pip-21.2.1

今度こそインストールできた。(Warning出てきたがpip直だたきは良くない?python勉強します。)

$ sudo pip3 install spleeter
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

〜略〜

Successfully installed absl-py-0.13.0 appdirs-1.4.4 astunparse-1.6.3 audioread-2.1.9 cachetools-4.2.2 charset-normalizer-2.0.3 click-7.1.2 contextvars-2.4 dataclasses-0.8 ffmpeg-python-0.2.0 future-0.18.2 gast-0.3.3 google-auth-1.33.1 google-auth-oauthlib-0.4.4 google-pasta-0.2.0 grpcio-1.39.0 h11-0.12.0 h2-3.2.0 h5py-2.10.0 hpack-3.0.0 httpcore-0.12.3 httpx-0.16.1 hyperframe-5.2.0 immutables-0.15 importlib-metadata-3.10.1 importlib-resources-4.1.1 joblib-1.0.1 keras-preprocessing-1.1.2 librosa-0.8.0 llvmlite-0.36.0 markdown-3.3.4 norbert-0.2.1 numba-0.53.1 numpy-1.18.5 oauthlib-3.1.1 opt-einsum-3.3.0 packaging-21.0 pandas-1.1.2 pooch-1.4.0 protobuf-3.17.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.26.0 requests-oauthlib-1.3.0 resampy-0.2.2 rfc3986-1.5.0 rsa-4.7.2 scikit-learn-0.24.2 scipy-1.4.1 setuptools-57.4.0 six-1.16.0 sniffio-1.2.0 soundfile-0.10.3.post1 spleeter-2.2.2 tensorboard-2.5.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.3.0 tensorflow-estimator-2.3.0 termcolor-1.1.0 threadpoolctl-2.2.0 typer-0.3.2 typing-extensions-3.10.0.0 werkzeug-2.0.1 wheel-0.36.2 wrapt-1.12.1 zipp-3.5.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
$ spleeter --version
Spleeter Version: 2.2.2

とりあえずGitHubのREADMEのクイックスタートに書いてあったサンプルで実際に試してみる。
が、またエラー...

$ wget https://github.com/deezer/spleeter/raw/master/audio_example.mp3
--2021-07-27 21:27:32--  https://github.com/deezer/spleeter/raw/master/audio_example.mp3
github.com (github.com) をDNSに問いあわせています... 140.82.114.3
github.com (github.com)|140.82.114.3|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: https://raw.githubusercontent.com/deezer/spleeter/master/audio_example.mp3 [続く]
--2021-07-27 21:27:33--  https://raw.githubusercontent.com/deezer/spleeter/master/audio_example.mp3
raw.githubusercontent.com (raw.githubusercontent.com) をDNSに問いあわせています... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 262867 (257K) [audio/mpeg]
`audio_example.mp3' に保存中

audio_example.mp3                                100%[=======================================================================================================>] 256.71K  --.-KB/s 時間 0.007s   

2021-07-27 21:27:33 (34.9 MB/s) - `audio_example.mp3' へ保存完了 [262867/262867]
$ spleeter separate -p spleeter:2stems -o output audio_example.mp3
Traceback (most recent call last):
  File "/usr/local/bin/spleeter", line 8, in <module>
    sys.exit(entrypoint())
  File "/usr/local/lib/python3.6/site-packages/spleeter/__main__.py", line 256, in entrypoint
    spleeter()
  File "/usr/local/lib/python3.6/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/typer/main.py", line 497, in wrapper
    return callback(**use_params)  # type: ignore
  File "/usr/local/lib/python3.6/site-packages/spleeter/__main__.py", line 114, in separate
    from .separator import Separator
  File "/usr/local/lib/python3.6/site-packages/spleeter/separator.py", line 27, in <module>
    from librosa.core import istft, stft
  File "/usr/local/lib/python3.6/site-packages/librosa/__init__.py", line 211, in <module>
    from . import core
  File "/usr/local/lib/python3.6/site-packages/librosa/core/__init__.py", line 5, in <module>
    from .convert import *  # pylint: disable=wildcard-import
  File "/usr/local/lib/python3.6/site-packages/librosa/core/convert.py", line 7, in <module>
    from . import notation
  File "/usr/local/lib/python3.6/site-packages/librosa/core/notation.py", line 8, in <module>
    from ..util.exceptions import ParameterError
  File "/usr/local/lib/python3.6/site-packages/librosa/util/__init__.py", line 84, in <module>
    from .files import *  # pylint: disable=wildcard-import
  File "/usr/local/lib/python3.6/site-packages/librosa/util/files.py", line 11, in <module>
    import pooch
  File "/usr/local/lib/python3.6/site-packages/pooch/__init__.py", line 10, in <module>
    from .core import Pooch, create, retrieve
  File "/usr/local/lib/python3.6/site-packages/pooch/core.py", line 17, in <module>
    import requests
  File "/usr/local/lib/python3.6/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/usr/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/usr/lib/python3.6/site-packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import (
ModuleNotFoundError: No module named 'urllib3.packages.six'

No module named 'urllib3.packages.six' でググるとurllib3アップデートするとよい的な情報があったので試してみる。

$ pip3 install -U urllib3
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: urllib3 in /usr/lib/python3.6/site-packages (1.24.2)
Collecting urllib3
  Downloading urllib3-1.26.6-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 9.3 MB/s 
Installing collected packages: urllib3
  WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /home/opc/.local/lib/python3.6/site-packages
  sysconfig: /home/opc/.local/lib64/python3.6/site-packages
  WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /home/opc/.local/include/python3.6m/urllib3
  sysconfig: /home/opc/.local/include/python3.6/urllib3
  WARNING: Additional context:
  user = True
  home = None
  root = None
  prefix = None
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /home/opc/.local/include/python3.6m/UNKNOWN
sysconfig: /home/opc/.local/include/python3.6/UNKNOWN
Successfully installed urllib3-1.26.6

もう一度やったら今度こそ成功...

$ spleeter separate -p spleeter:2stems -o output audio_example.mp3
INFO:spleeter:Downloading model archive https://github.com/deezer/spleeter/releases/download/v1.4.0/2stems.tar.gz
INFO:spleeter:Validating archive checksum
INFO:spleeter:Extracting downloaded 2stems archive
INFO:spleeter:2stems model file(s) extracted
INFO:spleeter:File output/audio_example/vocals.wav written succesfully
INFO:spleeter:File output/audio_example/accompaniment.wav written succesfully
$ ll output/audio_example/
合計 3752
-rw-rw-r--. 1 opc opc 1919406  7月 27 21:39 accompaniment.wav
-rw-rw-r--. 1 opc opc 1919406  7月 27 21:39 vocals.wav

実際の音源で試してみる

StudioOneから対象のパート(バックで他の楽器が流れてしまっているやつ)をmp3でエクスポート。とりあえずscpでサーバーへ送る。

# ローカル環境のmacOSターミナルから
$ scp -i <秘密鍵> *.mp3 opc@<PublicIP>:/home/opc/
Fair_And_Warmer_AS1.mp3       100% 1633KB  82.4KB/s   00:19    
Fair_And_Warmer_Tb1.mp3       100% 1633KB  98.8KB/s   00:16    
Time_Stream_AS1.mp3           100% 1652KB 165.0KB/s   00:10    
Time_Stream_Tb1.mp3           100% 1652KB 134.0KB/s   00:12    

こちらspleeter separate --helpを参考にコマンド試してみるも強制終了...
どうやらメモリ不足のときにそうなることがあるそうで...

$ spleeter separate -o FairAndWarmer_AS1 -p spleeter:5stems Fair_And_Warmer_AS1.mp3
INFO:spleeter:Downloading model archive https://github.com/deezer/spleeter/releases/download/v1.4.0/5stems.tar.gz
INFO:spleeter:Validating archive checksum
INFO:spleeter:Extracting downloaded 5stems archive
INFO:spleeter:5stems model file(s) extracted
強制終了  # 残念...
$ spleeter separate -o TimeStream_Tb1 -p spleeter:5stems Time_Stream_Tb1.mp3 
強制終了  # もう少し短い音源でもダメ...
$ spleeter separate -o TimeStream_Tb1 -p spleeter:4stems Time_Stream_Tb1.mp3
INFO:spleeter:Downloading model archive https://github.com/deezer/spleeter/releases/download/v1.4.0/4stems.tar.gz
INFO:spleeter:Validating archive checksum
INFO:spleeter:Extracting downloaded 4stems archive
INFO:spleeter:4stems model file(s) extracted
強制終了  # 分割するアイテム数減らしてもダメ...

たしかにメモリは最大まで使ってしまってるみたいです...
20210727_spleeter_1.png

まとめ

残念ながらOCIのAlwaysFreeインスタンスではSpleeterを使うには非力すぎたようです。
Linuxの方がセットアップが簡単だと思ったから挑戦してみましたが、意外とハマりポイントが多い&結局使えずとあんまりな結果でした。

ただ、コマンドを実行させるところまではいけているので、インスタンスを有料のメモリ多いやつに変更したらたぶん行けるのではないかと思います。

追記

仕方ないのでMacかWindowsで環境作ってリトライするかと思っていたところ、こんな素晴らしい記事&ツールがあると知りました。ツールの素晴らしさもさることながらGoogle Colaboratoryの存在も初めて知り、とても興味深いなと思いました。いろいろ調べてみよう。

ちなみにこちらのツールで実際に5パートへ分割してみたところ、期待通りの結果は得られず。トレーニングさせることもできるようなので、そうやってやっていくしかないか...
いろいろ調べるきっかけになっていい経験だったなと思うことにしました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0