offline-api.h
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// sherpa-onnx/sharp-api/offline-api.h
//
// Copyright (c) 2023 Manyeyes Corporation
#pragma once
#include <list>
namespace sherpa_onnx
{
/// Please refer to
/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
/// to download pre-trained models. That is, you can find encoder-xxx.onnx
/// decoder-xxx.onnx, joiner-xxx.onnx, and tokens.txt for this struct
/// from there.
typedef struct SherpaOnnxOfflineTransducer {
const char* encoder_filename;
const char* decoder_filename;
const char* joiner_filename;
} SherpaOnnxOfflineTransducer;
typedef struct SherpaOnnxOfflineParaformer {
const char* model;
}SherpaOnnxOfflineParaformer;
typedef struct SherpaOnnxOfflineNemoEncDecCtc {
const char* model;
}SherpaOnnxOfflineNemoEncDecCtc;
typedef struct SherpaOnnxOfflineModelConfig {
SherpaOnnxOfflineTransducer transducer;
SherpaOnnxOfflineParaformer paraformer;
SherpaOnnxOfflineNemoEncDecCtc nemo_ctc;
const char* tokens;
const int32_t num_threads;
const bool debug;
} SherpaOnnxOfflineModelConfig;
/// It expects 16 kHz 16-bit single channel wave format.
typedef struct SherpaOnnxFeatureConfig {
/// Sample rate of the input data. MUST match the one expected
/// by the model. For instance, it should be 16000 for models provided
/// by us.
int32_t sample_rate;
/// Feature dimension of the model.
/// For instance, it should be 80 for models provided by us.
int32_t feature_dim;
} SherpaOnnxFeatureConfig;
typedef struct SherpaOnnxOfflineRecognizerConfig {
SherpaOnnxFeatureConfig feat_config;
SherpaOnnxOfflineModelConfig model_config;
/// Possible values are: greedy_search, modified_beam_search
const char* decoding_method;
} SherpaOnnxOfflineRecognizerConfig;
typedef struct SherpaOnnxOfflineRecognizerResult {
// Recognition results.
// For English, it consists of space separated words.
// For Chinese, it consists of Chinese words without spaces.
char* text;
int text_len;
// Decoded results at the token level.
// For instance, for BPE-based models it consists of a list of BPE tokens.
// std::vector<std::string> tokens;
// timestamps.size() == tokens.size()
// timestamps[i] records the time in seconds when tokens[i] is decoded.
// std::vector<float> timestamps;
} SherpaOnnxOfflineRecognizerResult;
/// Note: OfflineRecognizer here means StreamingRecognizer.
/// It does not need to access the Internet during recognition.
/// Everything is run locally.
typedef struct SherpaOnnxOfflineRecognizer SherpaOnnxOfflineRecognizer;
typedef struct SherpaOnnxOfflineStream SherpaOnnxOfflineStream;
extern "C" __declspec(dllexport)
SherpaOnnxOfflineRecognizer * __stdcall CreateOfflineRecognizer(
const SherpaOnnxOfflineRecognizerConfig * config);
extern "C" __declspec(dllexport)
SherpaOnnxOfflineStream * __stdcall CreateOfflineStream(
SherpaOnnxOfflineRecognizer * sherpaOnnxOfflineRecognizer);
extern "C" __declspec(dllexport)
void __stdcall AcceptWaveform(
SherpaOnnxOfflineStream * stream, int32_t sample_rate,
const float* samples, int32_t samples_size);
extern "C" __declspec(dllexport)
void __stdcall DecodeOfflineStream(
SherpaOnnxOfflineRecognizer * recognizer,
SherpaOnnxOfflineStream * stream);
extern "C" __declspec(dllexport)
void __stdcall DecodeMultipleOfflineStreams(
SherpaOnnxOfflineRecognizer * recognizer,
SherpaOnnxOfflineStream * *streams, int32_t n);
extern "C" __declspec(dllexport)
SherpaOnnxOfflineRecognizerResult * __stdcall GetOfflineStreamResult(
SherpaOnnxOfflineStream * stream);
extern "C" __declspec(dllexport)
void __stdcall DestroyOfflineRecognizer(
SherpaOnnxOfflineRecognizer * recognizer);
extern "C" __declspec(dllexport)
void __stdcall DestroyOfflineStream(
SherpaOnnxOfflineStream * stream);
extern "C" __declspec(dllexport)
void __stdcall DestroyOfflineRecognizerResult(
SherpaOnnxOfflineRecognizerResult * r);
}// namespace sherpa_onnx