--- library_name: transformers license: other license_name: mit-apache-2.0-and-bsd-3-clause license_link: LICENSE pipeline_tag: feature-extraction tags: - audio - resemblyzer - speaker-embedding - speaker-verification --- # Resemblyzer [`resemble-ai/Resemblyzer`](https://github.com/resemble-ai/Resemblyzer), adapted to use with only `torch`, `torchaudio`, and `transformers`. ```python 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: ```python 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`.