Resemblyzer

resemble-ai/Resemblyzer, adapted to use with only torch, torchaudio, and transformers.

import soundfile as sf
import torch
from transformers import AutoModel

device = "cuda" if torch.cuda.is_available() else "cpu"
wav, sr = sf.read("audio.wav", dtype="float32")
wav = torch.from_numpy(wav)
model = AutoModel.from_pretrained(
    "prj-beatrice/resemblyzer-torch-native", trust_remote_code=True
).eval().to(device)

with torch.inference_mode():
    embedding = model(wav.to(device), sampling_rate=sr).embeddings[0]

The result matches this code:

from resemblyzer import VoiceEncoder, preprocess_wav

# Non-16 kHz input is resampled differently, so exact agreement is not expected.
assert sr == 16_000
reference = torch.from_numpy(
    VoiceEncoder().embed_utterance(preprocess_wav("audio.wav"))
)
torch.testing.assert_close(embedding.cpu(), reference)

Padded batches use a waveform tensor [batch_size, max_length] and an input_lengths tensor [batch_size].

License

Resemblyzer components are Apache-2.0, WebRTC VAD components are BSD-3-Clause, and the wrapper is MIT-licensed; see LICENSE.

Downloads last month
36
Safetensors
Model size
1.43M params
Tensor type
I64
·
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support