Add endpointing (#54)

This commit is contained in:
Fangjun Kuang
2023-02-22 15:35:55 +08:00
committed by GitHub
parent 1c6f79f096
commit 124384369a
23 changed files with 2190 additions and 21 deletions

View File

@@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include "sherpa-onnx/csrc/endpoint.h"
#include "sherpa-onnx/csrc/features.h"
#include "sherpa-onnx/csrc/online-stream.h"
#include "sherpa-onnx/csrc/online-transducer-model-config.h"
@@ -22,13 +23,21 @@ struct OnlineRecognizerConfig {
FeatureExtractorConfig feat_config;
OnlineTransducerModelConfig model_config;
std::string tokens;
EndpointConfig endpoint_config;
bool enable_endpoint;
OnlineRecognizerConfig() = default;
OnlineRecognizerConfig(const FeatureExtractorConfig &feat_config,
const OnlineTransducerModelConfig &model_config,
const std::string &tokens)
: feat_config(feat_config), model_config(model_config), tokens(tokens) {}
const std::string &tokens,
const EndpointConfig &endpoint_config,
bool enable_endpoint)
: feat_config(feat_config),
model_config(model_config),
tokens(tokens),
endpoint_config(endpoint_config),
enable_endpoint(enable_endpoint) {}
std::string ToString() const;
};
@@ -48,7 +57,7 @@ class OnlineRecognizer {
bool IsReady(OnlineStream *s) const;
/** Decode a single stream. */
void DecodeStream(OnlineStream *s) {
void DecodeStream(OnlineStream *s) const {
OnlineStream *ss[1] = {s};
DecodeStreams(ss, 1);
}
@@ -58,9 +67,18 @@ class OnlineRecognizer {
* @param ss Pointer array containing streams to be decoded.
* @param n Number of streams in `ss`.
*/
void DecodeStreams(OnlineStream **ss, int32_t n);
void DecodeStreams(OnlineStream **ss, int32_t n) const;
OnlineRecognizerResult GetResult(OnlineStream *s);
OnlineRecognizerResult GetResult(OnlineStream *s) const;
// Return true if we detect an endpoint for this stream.
// Note: If this function returns true, you usually want to
// invoke Reset(s).
bool IsEndpoint(OnlineStream *s) const;
// Clear the state of this stream. If IsEndpoint(s) returns true,
// after calling this function, IsEndpoint(s) will return false
void Reset(OnlineStream *s) const;
private:
class Impl;