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

Add runtime support for wespeaker models #516

Merged
merged 11 commits into from
Jan 9, 2024

Conversation

csukuangfj
Copy link
Collaborator

Usage

Download test files

wget https://github.com/k2-fsa/sherpa-onnx/releases/download/speaker-recongition-models/zh_cnceleb_resnet34.onnx

wget https://huggingface.co/openspeech/wespeaker-models/resolve/main/test_wavs/00001_spk1.wav
wget https://huggingface.co/openspeech/wespeaker-models/resolve/main/test_wavs/00024_spk1.wav
wget https://huggingface.co/openspeech/wespeaker-models/resolve/main/test_wavs/00010_spk2.wav

Test code

#!/usr/bin/env python3

import sherpa_onnx
import torchaudio
import torch


def load_audio(filename):
    samples, sample_rate = torchaudio.load(filename)
    return samples[0].contiguous().numpy(), sample_rate


def main():
    model = "./zh_cnceleb_resnet34.onnx"
    config = sherpa_onnx.SpeakerEmbeddingExtractorConfig(
        model=model,
        num_threads=1,
        debug=True,
        provider="cpu",
    )
    print(config)
    extractor = sherpa_onnx.SpeakerEmbeddingExtractor(config)

    samples0, sample_rate0 = load_audio("./00001_spk1.wav")
    samples1, sample_rate1 = load_audio("./00024_spk1.wav")
    #  samples1, sample_rate1 = load_audio("./00010_spk2.wav")

    s0 = extractor.create_stream()
    s1 = extractor.create_stream()

    s0.accept_waveform(sample_rate=sample_rate0, waveform=samples0)
    s1.accept_waveform(sample_rate=sample_rate1, waveform=samples1)

    while extractor.is_ready(s0):
        embedding0 = extractor.compute(s0)

    while extractor.is_ready(s1):
        embedding1 = extractor.compute(s1)

    embedding0 = torch.tensor(embedding0)
    embedding1 = torch.tensor(embedding1)
    print(torch.nn.functional.cosine_similarity(embedding0, embedding1, dim=0))


if __name__ == "__main__":
    main()

TODOs

  • VAD + speaker embedding model for speaker diarization (who spoke when)
  • VAD + speaker embedding model + ASR (who spoke when and what)
  • Android Demo
  • APIs for other languages, e.g., C/Go/C#, etc.

@csukuangfj csukuangfj merged commit 5526691 into k2-fsa:master Jan 9, 2024
2 of 3 checks passed
@csukuangfj csukuangfj deleted the speaker-embedding-extractor branch January 9, 2024 14:06
@csukuangfj
Copy link
Collaborator Author

A demo video for this pull-request can be found at
https://www.bilibili.com/video/BV1nC4y1Y7Kk/

(Note that it is in Chinese.)

Screenshot 2024-01-09 at 23 07 30

XiaYucca pushed a commit to XiaYucca/sherpa-onnx that referenced this pull request Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant