Add runtime support for wespeaker models (#516)

This commit is contained in:
Fangjun Kuang
2024-01-09 22:06:08 +08:00
committed by GitHub
parent 902b21894b
commit 55266918c8
27 changed files with 1291 additions and 4 deletions

View File

@@ -0,0 +1,67 @@
// sherpa-onnx/csrc/speaker-embedding-extractor.h
//
// Copyright (c) 2023 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_SPEAKER_EMBEDDING_EXTRACTOR_H_
#define SHERPA_ONNX_CSRC_SPEAKER_EMBEDDING_EXTRACTOR_H_
#include <memory>
#include <string>
#include <vector>
#include "sherpa-onnx/csrc/online-stream.h"
#include "sherpa-onnx/csrc/parse-options.h"
namespace sherpa_onnx {
struct SpeakerEmbeddingExtractorConfig {
std::string model;
int32_t num_threads = 1;
bool debug = false;
std::string provider = "cpu";
SpeakerEmbeddingExtractorConfig() = default;
SpeakerEmbeddingExtractorConfig(const std::string &model, int32_t num_threads,
bool debug, const std::string &provider)
: model(model),
num_threads(num_threads),
debug(debug),
provider(provider) {}
void Register(ParseOptions *po);
bool Validate() const;
std::string ToString() const;
};
class SpeakerEmbeddingExtractorImpl;
class SpeakerEmbeddingExtractor {
public:
explicit SpeakerEmbeddingExtractor(
const SpeakerEmbeddingExtractorConfig &config);
~SpeakerEmbeddingExtractor();
// Return the dimension of the embedding
int32_t Dim() const;
// Create a stream to accept audio samples and compute features
std::unique_ptr<OnlineStream> CreateStream() const;
// Return true if there are feature frames in OnlineStream that
// can be used to compute embeddings.
bool IsReady(OnlineStream *s) const;
// Compute the speaker embedding from the available unprocessed features
// of the given stream
//
// You have to ensure IsReady(s) returns true before you call this method.
std::vector<float> Compute(OnlineStream *s) const;
private:
std::unique_ptr<SpeakerEmbeddingExtractorImpl> impl_;
};
} // namespace sherpa_onnx
#endif // SHERPA_ONNX_CSRC_SPEAKER_EMBEDDING_EXTRACTOR_H_