sherpa-onnx C API 1.0
Public C API and C++ wrapper for sherpa-onnx
Loading...
Searching...
No Matches
sherpa_onnx::cxx::ForcedAligner Class Reference

RAII wrapper for a forced aligner. More...

#include <cxx-api.h>

Inheritance diagram for sherpa_onnx::cxx::ForcedAligner:
Collaboration diagram for sherpa_onnx::cxx::ForcedAligner:

Public Member Functions

void Destroy (const SherpaOnnxForcedAligner *p) const
 Destroy the wrapped C handle.
OfflineStream CreateStream () const
 Create an utterance stream.
ForcedAlignmentResult Compute (const OfflineStream &stream, const std::string &text) const
 Compute the alignment of one utterance.
Public Member Functions inherited from sherpa_onnx::cxx::MoveOnly< ForcedAligner, SherpaOnnxForcedAligner >
 MoveOnly ()=default
 Construct an empty wrapper.
 ~MoveOnly ()
 Destroy the wrapped handle if present.
MoveOnly & operator= (const MoveOnly &)=delete
const SherpaOnnxForcedAligner * Get () const
 Return the wrapped raw pointer without transferring ownership.
const SherpaOnnxForcedAligner * Release ()
 Release ownership of the wrapped raw pointer.

Static Public Member Functions

static ForcedAligner Create (const ForcedAlignerConfig &config)
 Create a forced aligner from a model directory and a pronunciation dictionary.

Additional Inherited Members

Protected Attributes inherited from sherpa_onnx::cxx::MoveOnly< ForcedAligner, SherpaOnnxForcedAligner >
const SherpaOnnxForcedAligner * p_

Detailed Description

Given a wave and its transcript, it computes the start/end time of every phone and word:

config.model_dir = "./english-mfa-v3.1.0";
config.lexicon = "./english-mfa-v3.1.0/lexicon.txt";
ForcedAligner aligner = ForcedAligner::Create(config);
OfflineStream stream = aligner.CreateStream();
// Optional: per-stream options, e.g. debug output of one utterance.
stream.SetOption("debug", "1");
stream.AcceptWaveform(wave.sample_rate, wave.samples.data(),
static_cast<int32_t>(wave.samples.size()));
ForcedAlignmentResult result = aligner.Compute(stream, text);
OfflineStream CreateStream() const
Create an utterance stream.
static ForcedAligner Create(const ForcedAlignerConfig &config)
Create a forced aligner from a model directory and a pronunciation dictionary.
ForcedAlignmentResult Compute(const OfflineStream &stream, const std::string &text) const
Compute the alignment of one utterance.
RAII wrapper for an offline decoding stream.
Definition cxx-api.h:785
void SetOption(const char *key, const char *value) const
Set a per-stream string option.
void AcceptWaveform(int32_t sample_rate, const float *samples, int32_t n) const
Provide the complete waveform for offline decoding.
Configuration of a forced aligner.
Definition cxx-api.h:893
The result of ForcedAligner::Compute().
Definition cxx-api.h:1000

Definition at line 1042 of file cxx-api.h.

Member Function Documentation

◆ Compute()

ForcedAlignmentResult sherpa_onnx::cxx::ForcedAligner::Compute ( const OfflineStream & stream,
const std::string & text ) const
Parameters
streamA stream created by CreateStream() and filled with a waveform.
textThe transcript of the whole utterance. Hanzi text is tokenized per character (multi-character dictionary keys give pronunciation context); anything else is split on whitespace. Punctuation is ignored.
Returns
The alignment result; empty (no tiers, empty textgrid) with a warning on stderr when the stream has no features, every word is out-of-vocabulary, or word boundaries cannot be recovered.

◆ Create()

ForcedAligner sherpa_onnx::cxx::ForcedAligner::Create ( const ForcedAlignerConfig & config)
static

◆ CreateStream()

OfflineStream sherpa_onnx::cxx::ForcedAligner::CreateStream ( ) const

Fill it with OfflineStream::AcceptWaveform(), then pass it to Compute().

◆ Destroy()

void sherpa_onnx::cxx::ForcedAligner::Destroy ( const SherpaOnnxForcedAligner * p) const

The documentation for this class was generated from the following file: