Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix Pretrained.load_audio #1303

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions speechbrain/pretrained/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,15 @@ def _prepare_modules(self, freeze_params):
for p in self.mods.parameters():
p.requires_grad = False

def load_audio(self, path, savedir="."):
def load_audio(self, path):
"""Load an audio file with this model"s input spec

When using a speech model, it is important to use the same type of data,
as was used to train the model. This means for example using the same
sampling rate and number of channels. It is, however, possible to
convert a file from a higher sampling rate to a lower one (downsampling).
Similarly, it is simple to downmix a stereo file to mono.
The path can be a local path, a web url, or a link to a huggingface repo.
"""
source, fl = split_path(path)
path = fetch(fl, source=source, savedir=savedir)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing it will avoid this problem but also deactivate other features ;-)
the bug fix needs to happen elsewhere, as this fix will break other things (e.g. resolving HuggingFace URLs)

signal, sr = torchaudio.load(str(path), channels_first=False)
return self.audio_normalizer(signal, sr)

Expand Down
17 changes: 17 additions & 0 deletions tests/unittests/test_interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import torch


def test_load_audio(tmpdir):
from speechbrain.pretrained.interfaces import Pretrained

verification = Pretrained.from_hparams(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still wondering about loading a 100+MB pretrained model here. I deleted my earlier comments on using a shorter pretrained model. All that is relevant here are these lines

        source, fl = split_path(path)
        path = fetch(fl, source=source, savedir=savedir)
        signal, sr = torchaudio.load(path, channels_first=False)

That's what needs to be tested for the fetch in pretrained interfaces.

source="speechbrain/spkrec-ecapa-voxceleb",
savedir=tmpdir.mkdir("savedir"),
)
audio1 = verification.load_audio(
"samples/voxceleb_samples/wav/id10002/xTV-jFAUKcw/00001.wav"
)
audio2 = verification.load_audio(
"samples/voxceleb_samples/wav/id10001/1zcIwhmdeo4/00001.wav"
)
assert not torch.equal(audio1, audio2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a final empty line
run ./tests/.run-linters.sh to see if there's more to be done regarding formatting