I am giving a try to a speech diarization project named diart
(based on hugging face models)
I follow the instructions using a miniconda
environment which are essentially:
conda create -n diart python=3.8
conda activate diart
conda install portaudio pysoundfile ffmpeg -c conda-forge
pip install diart
# + register some pyannote stuff on hugging face
# requiring hugging face CLI instructions for API token
However, I keep bumping into python import error:
ImportError: FFmpeg libraries are not found. Please install FFmpeg.
Trace:
>>> from diart.sources import MicrophoneAudioSource
Traceback (most recent call last):
File "F:DEVminiconda3envsdiartlibsite-packagestorchaudio_extension.py", line 71, in _init_ffmpeg
_load_lib("libtorchaudio_ffmpeg")
File "F:DEVminiconda3envsdiartlibsite-packagestorchaudio_extension.py", line 52, in _load_lib
torch.ops.load_library(path)
File "F:DEVminiconda3envsdiartlibsite-packagestorch_ops.py", line 573, in load_library
ctypes.CDLL(path)
File "F:DEVminiconda3envsdiartlibctypes__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'F:DEVminiconda3envsdiartLibsite-packagestorchaudioliblibtorchaudio_ffmpeg.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:DEVminiconda3envsdiartlibsite-packagesdiartsources.py", line 11, in <module>
from torchaudio.io import StreamReader
File "F:DEVminiconda3envsdiartlibsite-packagestorchaudioio__init__.py", line 21, in __getattr__
torchaudio._extension._init_ffmpeg()
File "F:DEVminiconda3envsdiartlibsite-packagestorchaudio_extension.py", line 73, in _init_ffmpeg
raise ImportError("FFmpeg libraries are not found. Please install FFmpeg.") from err
ImportError: FFmpeg libraries are not found. Please install FFmpeg.
It is my first time with Torch, and I do believe the issue is with a missing TorchAudio specific library.
The python file that raises the exception states:
def _init_ffmpeg(): # line 60
# ...
try:
_load_lib("libtorchaudio_ffmpeg")
except OSError as err:
raise ImportError("FFmpeg libraries are not found. Please install FFmpeg.") from err #<=== line 73 : the exception
# ...
Below you will find many details concerning the environment.
Question
Am I missing something ? What should I do to use this project ?
Additionnal info
The resulting environment setup (using Miniconda Powershell) in admin mode.
FFMPEG is confirmed in the path to be seen from the conda env install:
(diart) PS C:Windowssystem32> get-command ffmpeg
CommandType Name Version Source
----------- ---- ------- ------
Application ffmpeg.exe 0.0.0.0 F:DEVminiconda3envsdiartLibrarybinffmpeg.exe
Python
(diart) PS C:Windowssystem32> python --version
Python 3.8.16
Conda env setup
(diart) PS C:Windowssystem32> conda --version
conda 23.3.1
(diart) PS C:Windowssystem32> conda list
# packages in environment at F:DEVminiconda3envsdiart:
#
# Name Version Build Channel
absl-py 1.4.0 pypi_0 pypi
aiohttp 3.8.4 pypi_0 pypi
aiosignal 1.3.1 pypi_0 pypi
alembic 1.10.4 pypi_0 pypi
antlr4-python3-runtime 4.9.3 pypi_0 pypi
aom 3.5.0 h63175ca_0 conda-forge
asteroid-filterbanks 0.4.0 pypi_0 pypi
async-timeout 4.0.2 pypi_0 pypi
attrs 23.1.0 pypi_0 pypi
audioread 3.0.0 pypi_0 pypi
backports-cached-property 1.0.2 pypi_0 pypi
bzip2 1.0.8 h8ffe710_4 conda-forge
ca-certificates 2022.12.7 h5b45459_0 conda-forge
cachetools 5.3.0 pypi_0 pypi
certifi 2022.12.7 pypi_0 pypi
cffi 1.15.1 py38h57701bc_3 conda-forge
charset-normalizer 3.1.0 pypi_0 pypi
click 8.1.3 pypi_0 pypi
cmaes 0.9.1 pypi_0 pypi
colorama 0.4.6 pypi_0 pypi
colorlog 6.7.0 pypi_0 pypi
commonmark 0.9.1 pypi_0 pypi
contourpy 1.0.7 pypi_0 pypi
cycler 0.11.0 pypi_0 pypi
decorator 5.1.1 pypi_0 pypi
diart 0.7.0 pypi_0 pypi
docopt 0.6.2 pypi_0 pypi
einops 0.3.2 pypi_0 pypi
expat 2.5.0 h63175ca_1 conda-forge
ffmpeg 5.1.2 gpl_h5b1d025_106 conda-forge
filelock 3.12.0 pypi_0 pypi
font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge
font-ttf-inconsolata 3.000 h77eed37_0 conda-forge
font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge
font-ttf-ubuntu 0.83 hab24e00_0 conda-forge
fontconfig 2.14.2 hbde0cde_0 conda-forge
fonts-conda-ecosystem 1 0 conda-forge
fonts-conda-forge 1 0 conda-forge
fonttools 4.39.3 pypi_0 pypi
freetype 2.12.1 h546665d_1 conda-forge
frozenlist 1.3.3 pypi_0 pypi
fsspec 2023.4.0 pypi_0 pypi
google-auth 2.17.3 pypi_0 pypi
google-auth-oauthlib 1.0.0 pypi_0 pypi
greenlet 2.0.2 pypi_0 pypi
grpcio 1.54.0 pypi_0 pypi
hmmlearn 0.2.8 pypi_0 pypi
huggingface-hub 0.14.1 pypi_0 pypi
hyperpyyaml 1.2.0 pypi_0 pypi
idna 3.4 pypi_0 pypi
importlib-metadata 6.6.0 pypi_0 pypi
importlib-resources 5.12.0 pypi_0 pypi
intel-openmp 2023.1.0 h57928b3_46319 conda-forge
joblib 1.2.0 pypi_0 pypi
julius 0.2.7 pypi_0 pypi
kiwisolver 1.4.4 pypi_0 pypi
lame 3.100 hcfcfb64_1003 conda-forge
libblas 3.9.0 16_win64_mkl conda-forge
libcblas 3.9.0 16_win64_mkl conda-forge
libexpat 2.5.0 h63175ca_1 conda-forge
libffi 3.4.2 h8ffe710_5 conda-forge
libflac 1.4.2 h63175ca_0 conda-forge
libhwloc 2.9.1 h51c2c0f_0 conda-forge
libiconv 1.17 h8ffe710_0 conda-forge
liblapack 3.9.0 16_win64_mkl conda-forge
libogg 1.3.4 h8ffe710_1 conda-forge
libopus 1.3.1 h8ffe710_1 conda-forge
libpng 1.6.39 h19919ed_0 conda-forge
librosa 0.9.2 pypi_0 pypi
libsndfile 1.2.0 h2628c91_0 conda-forge
libsqlite 3.40.0 hcfcfb64_1 conda-forge
libvorbis 1.3.7 h0e60522_0 conda-forge
libxml2 2.10.4 hc3477c8_0 conda-forge
libzlib 1.2.13 hcfcfb64_4 conda-forge
llvmlite 0.39.1 pypi_0 pypi
mako 1.2.4 pypi_0 pypi
markdown 3.4.3 pypi_0 pypi
markupsafe 2.1.2 pypi_0 pypi
matplotlib 3.7.1 pypi_0 pypi
mkl 2022.1.0 h6a75c08_874 conda-forge
mpg123 1.31.3 h63175ca_0 conda-forge
mpmath 1.3.0 pypi_0 pypi
multidict 6.0.4 pypi_0 pypi
networkx 2.8.8 pypi_0 pypi
numba 0.56.4 pypi_0 pypi
numpy 1.23.5 pypi_0 pypi
oauthlib 3.2.2 pypi_0 pypi
omegaconf 2.3.0 pypi_0 pypi
openh264 2.3.1 h63175ca_2 conda-forge
openssl 3.1.0 hcfcfb64_2 conda-forge
optuna 3.1.1 pypi_0 pypi
packaging 23.1 pypi_0 pypi
pandas 2.0.1 pypi_0 pypi
pillow 9.5.0 pypi_0 pypi
pip 23.1.2 pyhd8ed1ab_0 conda-forge
platformdirs 3.5.0 pypi_0 pypi
pooch 1.7.0 pypi_0 pypi
portaudio 19.6.0 h63175ca_7 conda-forge
primepy 1.3 pypi_0 pypi
protobuf 3.20.1 pypi_0 pypi
pthreads-win32 2.9.1 hfa6e2cd_3 conda-forge
pyannote-audio 2.1.1 pypi_0 pypi
pyannote-core 4.5 pypi_0 pypi
pyannote-database 4.1.3 pypi_0 pypi
pyannote-metrics 3.2.1 pypi_0 pypi
pyannote-pipeline 2.3 pypi_0 pypi
pyasn1 0.5.0 pypi_0 pypi
pyasn1-modules 0.3.0 pypi_0 pypi
pycparser 2.21 pyhd8ed1ab_0 conda-forge
pydeprecate 0.3.2 pypi_0 pypi
pygments 2.15.1 pypi_0 pypi
pyparsing 3.0.9 pypi_0 pypi
python 3.8.16 h4de0772_1_cpython conda-forge
python-dateutil 2.8.2 pypi_0 pypi
python_abi 3.8 3_cp38 conda-forge
pytorch-lightning 1.6.5 pypi_0 pypi
pytorch-metric-learning 1.7.3 pypi_0 pypi
pytz 2023.3 pypi_0 pypi
pyyaml 6.0 pypi_0 pypi
requests 2.29.0 pypi_0 pypi
requests-oauthlib 1.3.1 pypi_0 pypi
resampy 0.4.2 pypi_0 pypi
rich 12.6.0 pypi_0 pypi
rsa 4.9 pypi_0 pypi
ruamel-yaml 0.17.21 pypi_0 pypi
ruamel-yaml-clib 0.2.7 pypi_0 pypi
rx 3.2.0 pypi_0 pypi
scikit-learn 1.2.2 pypi_0 pypi
scipy 1.10.1 pypi_0 pypi
semver 2.13.0 pypi_0 pypi
sentencepiece 0.1.98 pypi_0 pypi
setuptools 67.7.2 pyhd8ed1ab_0 conda-forge
shellingham 1.5.0.post1 pypi_0 pypi
simplejson 3.19.1 pypi_0 pypi
singledispatchmethod 1.0 pypi_0 pypi
six 1.16.0 pypi_0 pypi
sortedcontainers 2.4.0 pypi_0 pypi
sounddevice 0.4.6 pypi_0 pypi
soundfile 0.10.3.post1 pypi_0 pypi
speechbrain 0.5.14 pypi_0 pypi
sqlalchemy 2.0.11 pypi_0 pypi
sqlite 3.40.0 hcfcfb64_1 conda-forge
svt-av1 1.4.1 h63175ca_0 conda-forge
sympy 1.11.1 pypi_0 pypi
tabulate 0.9.0 pypi_0 pypi
tbb 2021.9.0 h91493d7_0 conda-forge
tensorboard 2.12.2 pypi_0 pypi
tensorboard-data-server 0.7.0 pypi_0 pypi
tensorboard-plugin-wit 1.8.1 pypi_0 pypi
threadpoolctl 3.1.0 pypi_0 pypi
tk 8.6.12 h8ffe710_0 conda-forge
torch 1.13.1 pypi_0 pypi
torch-audiomentations 0.11.0 pypi_0 pypi
torch-pitch-shift 1.2.4 pypi_0 pypi
torchaudio 0.13.1 pypi_0 pypi
torchmetrics 0.11.4 pypi_0 pypi
torchvision 0.14.1 pypi_0 pypi
tqdm 4.65.0 pypi_0 pypi
typer 0.7.0 pypi_0 pypi
typing-extensions 4.5.0 pypi_0 pypi
tzdata 2023.3 pypi_0 pypi
ucrt 10.0.22621.0 h57928b3_0 conda-forge
urllib3 1.26.15 pypi_0 pypi
vc 14.3 h3d8a991_11 conda-forge
vs2015_runtime 14.34.31931 h4c5c07a_11 conda-forge
websocket-client 1.5.1 pypi_0 pypi
websocket-server 0.6.4 pypi_0 pypi
werkzeug 2.3.1 pypi_0 pypi
wheel 0.40.0 pyhd8ed1ab_0 conda-forge
x264 1!164.3095 h8ffe710_2 conda-forge
x265 3.5 h2d74725_3 conda-forge
xz 5.2.6 h8d14728_0 conda-forge
yarl 1.9.2 pypi_0 pypi
zipp 3.15.0 pypi_0 pypi
Things I tried
Follow PyTorch audio build process as described here using Visual Studio 2022 Community powershell for developper x64
Enter-VsDevShell 7c1743f6 -Arch amd64 # if necessary, for Visual Studio build tools x64 within power shell for developpers
#
git clone https://github.com/pytorch/audio
cd audio
set USE_FFMPEG=1
# python setup.py develop
python setup.py develop --verbose
Output error slightly truncated due to post size overflow (30_000 char):
# redacted due to post char limit...
rir.cpp.obj : error LNK2019: symbole externe non résolu "__declspec(dllimport) class at::Tensor __cdecl at::fft_irfft(class at::Tensor const &,class c10::optional<__int64>,__int64,class c10::optional<class c10::basic_string_view<char> >)" (__imp_?fft_irfft@at@@YA?AVTensor@1@AEBV21@V?$optional@_J@c10@@_JV?$optional@V?$basic_string_view@D@c10@@@4@@Z) référencé dans la fonction "void __cdecl torchaudio::rir::`anonymous namespace'::make_rir_filter_impl<float>(class at::Tensor &,double,__int64,class at::Tensor &)" (??$make_rir_filter_impl@M@?A0xcc00d006@rir@torchaudio@@YAXAEAVTensor@at@@N_J0@Z)
torchaudiocsrclibtorchaudio.pyd : fatal error LNK1120: 12 externes non résolus
ninja: build stopped: subcommand failed.
Tests
1. @Brock Brown ==> what if conda uninstall ffmpeg
?
(diart) PS C:Windowssystem32> conda uninstall ffmpeg
(diart) PS C:Windowssystem32> python
Python 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from diart.sources import *
# redacted due to post char limit...
from _sounddevice import ffi as _ffi
File "F:DEVminiconda3envsdiartlibsite-packages_sounddevice.py", line 2, in <module>
import _cffi_backend
ModuleNotFoundError: No module named '_cffi_backend'
(diart) PS C:Windowssystem32> Get-Command ffmpeg
CommandType Name Version Source
----------- ---- ------- ------
Application ffmpeg.exe 1.0.0.0 C:ProgramDatachocolateybinffmpeg.exe
(diart) PS C:Windowssystem32> ffmpeg --version
ffmpeg version 6.0-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
FFMPEG version
according to this link it may be preferrable to use ffmpeg <4.4.
I tried that using chocolatey install ffmpeg=4.3 without success.
2
Answers
TorchAudio 0.13.1 supports FFmpeg v4.1 – v4.4. You have FFmpeg 5.1.
Installing FFmpeg v4 should resolve the problem. (v4.3 or v4.4 is better).
conda install ‘ffmpeg<4.4’
This installation helps to work successfully.