From 422378d848bd7ecb03ab564e7072d3199344506b Mon Sep 17 00:00:00 2001 From: Adel Moumen Date: Wed, 28 Feb 2024 22:05:16 +0100 Subject: [PATCH 1/6] update import to comply with any version of SB --- pyannote/audio/pipelines/speaker_verification.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pyannote/audio/pipelines/speaker_verification.py b/pyannote/audio/pipelines/speaker_verification.py index c49468a79..3548ac974 100644 --- a/pyannote/audio/pipelines/speaker_verification.py +++ b/pyannote/audio/pipelines/speaker_verification.py @@ -22,6 +22,7 @@ import warnings from functools import cached_property +from packaging import version from pathlib import Path from typing import Optional, Text, Union @@ -42,9 +43,17 @@ backend = torchaudio.get_audio_backend() try: - from speechbrain.pretrained import ( - EncoderClassifier as SpeechBrain_EncoderClassifier, - ) + import speechbrain + # SpeechBrain 1.0 changed the inference API to be `speechbrain.inference` + # instead of `speechbrain.pretrained`. + if version.parse(speechbrain.__version__) >= version.parse("1.0.0"): + from speechbrain.inference import ( + EncoderClassifier as SpeechBrain_EncoderClassifier, + ) + else: + from speechbrain.pretrained import ( + EncoderClassifier as SpeechBrain_EncoderClassifier, + ) SPEECHBRAIN_IS_AVAILABLE = True except ImportError: From ba04fcd9c30eddca167e60cfe3137dfe4a4418ca Mon Sep 17 00:00:00 2001 From: Adel Moumen Date: Fri, 1 Mar 2024 13:18:58 +0100 Subject: [PATCH 2/6] update requirements / speaker_verif for sb 1.0 --- pyannote/audio/pipelines/speaker_verification.py | 15 +++------------ requirements.txt | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/pyannote/audio/pipelines/speaker_verification.py b/pyannote/audio/pipelines/speaker_verification.py index 3548ac974..538908384 100644 --- a/pyannote/audio/pipelines/speaker_verification.py +++ b/pyannote/audio/pipelines/speaker_verification.py @@ -22,7 +22,6 @@ import warnings from functools import cached_property -from packaging import version from pathlib import Path from typing import Optional, Text, Union @@ -43,17 +42,9 @@ backend = torchaudio.get_audio_backend() try: - import speechbrain - # SpeechBrain 1.0 changed the inference API to be `speechbrain.inference` - # instead of `speechbrain.pretrained`. - if version.parse(speechbrain.__version__) >= version.parse("1.0.0"): - from speechbrain.inference import ( - EncoderClassifier as SpeechBrain_EncoderClassifier, - ) - else: - from speechbrain.pretrained import ( - EncoderClassifier as SpeechBrain_EncoderClassifier, - ) + from speechbrain.inference import ( + EncoderClassifier as SpeechBrain_EncoderClassifier, + ) SPEECHBRAIN_IS_AVAILABLE = True except ImportError: diff --git a/requirements.txt b/requirements.txt index 7e71fe024..fff049385 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ pytorch_metric_learning >= 2.1.0 rich >= 12.0.0 semver >= 3.0.0 soundfile >= 0.12.1 -speechbrain >= 0.5.14 +speechbrain >= 1.0.0 tensorboardX >= 2.6 torch >= 2.0.0 torch_audiomentations >= 0.11.0 From efc7017b6aaa60749ba8a4a80d1bf87ae90236f3 Mon Sep 17 00:00:00 2001 From: Adel Moumen Date: Sat, 2 Mar 2024 16:48:08 +0100 Subject: [PATCH 3/6] add unittest speechbrain --- tests/test_speechbrain.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/test_speechbrain.py diff --git a/tests/test_speechbrain.py b/tests/test_speechbrain.py new file mode 100644 index 000000000..ab609b9c2 --- /dev/null +++ b/tests/test_speechbrain.py @@ -0,0 +1,14 @@ +from speechbrain.inference import EncoderClassifier + + +def test_import_speechbrain_encoder_classifier(cache): + """This is a simple test that check if speechbrain + EncoderClassifier can be imported. It does not check + if the model is working properly. + """ + + model = EncoderClassifier.from_hparams( + source="speechbrain/spkrec-ecapa-voxceleb", + savedir=cache, + ) + assert isinstance(model, EncoderClassifier) From 5473f8a59ce823b254b8e9ea0fe4fb854786c03f Mon Sep 17 00:00:00 2001 From: Adel Moumen Date: Mon, 11 Mar 2024 18:34:05 +0100 Subject: [PATCH 4/6] fix test --- tests/test_speechbrain.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_speechbrain.py b/tests/test_speechbrain.py index ab609b9c2..067cdd274 100644 --- a/tests/test_speechbrain.py +++ b/tests/test_speechbrain.py @@ -1,6 +1,13 @@ +from tempfile import mkstemp + +import pytest from speechbrain.inference import EncoderClassifier +@pytest.fixture() +def cache(): + return mkstemp()[1] + def test_import_speechbrain_encoder_classifier(cache): """This is a simple test that check if speechbrain EncoderClassifier can be imported. It does not check From 0d745d5964d6586db07bac636e8ff4a1ebdfc8a4 Mon Sep 17 00:00:00 2001 From: Adel Moumen Date: Mon, 11 Mar 2024 18:51:54 +0100 Subject: [PATCH 5/6] fix test --- tests/test_speechbrain.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_speechbrain.py b/tests/test_speechbrain.py index 067cdd274..0ac9b60cf 100644 --- a/tests/test_speechbrain.py +++ b/tests/test_speechbrain.py @@ -1,12 +1,11 @@ -from tempfile import mkstemp - +import tempfile import pytest from speechbrain.inference import EncoderClassifier @pytest.fixture() def cache(): - return mkstemp()[1] + return tempfile.mkdtemp() def test_import_speechbrain_encoder_classifier(cache): """This is a simple test that check if speechbrain From 2f9dbbb300bc1df21932d2ea401f1e7200813eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20BREDIN?= Date: Wed, 19 Jun 2024 13:09:52 +0200 Subject: [PATCH 6/6] doc: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83601072e..2b54ab746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - fix: fix support for `numpy==2.x` ([@ibevers](https://github.com/ibevers/)) +- fix: fix support for `speechbrain==1.x` ([@Adel-Moumen](https://github.com/Adel-Moumen/)) ### Breaking changes