1#![allow(non_snake_case)]
4#![allow(non_camel_case_types)]
5#![allow(non_upper_case_globals)]
6
7#[repr(C)]
8#[derive(Debug, Copy, Clone)]
9pub struct VoskModel {
10 _unused: [u8; 0],
11}
12
13#[repr(C)]
14#[derive(Debug, Copy, Clone)]
15pub struct VoskSpkModel {
16 _unused: [u8; 0],
17}
18
19#[repr(C)]
20#[derive(Debug, Copy, Clone)]
21pub struct VoskRecognizer {
22 _unused: [u8; 0],
23}
24
25#[repr(C)]
26#[derive(Debug, Copy, Clone)]
27pub struct VoskBatchModel {
28 _unused: [u8; 0],
29}
30
31#[repr(C)]
32#[derive(Debug, Copy, Clone)]
33pub struct VoskBatchRecognizer {
34 _unused: [u8; 0],
35}
36
37#[cfg_attr(not(target_os = "windows"), link(name = "vosk"))]
38#[cfg_attr(target_os = "windows", link(name = "libvosk"))]
39extern "C" {
40 #[doc = " Loads model data from the file and returns the model object"]
41 #[doc = ""]
42 #[doc = " @param model_path: the path of the model on the filesystem"]
43 #[doc = " @returns model object or NULL if problem occured"]
44 pub fn vosk_model_new(model_path: *const ::std::os::raw::c_char) -> *mut VoskModel;
45
46 #[doc = " Releases the model memory"]
47 #[doc = ""]
48 #[doc = " The model object is reference-counted so if some recognizer"]
49 #[doc = " depends on this model, model might still stay alive. When"]
50 #[doc = " last recognizer is released, model will be released too."]
51 pub fn vosk_model_free(model: *mut VoskModel);
52
53 #[doc = " Check if a word can be recognized by the model"]
54 #[doc = " @param word: the word"]
55 #[doc = " @returns the word symbol if @param word exists inside the model"]
56 #[doc = " or -1 otherwise."]
57 #[doc = " Reminding that word symbol 0 is for \\<epsilon\\>"]
58 pub fn vosk_model_find_word(
59 model: *mut VoskModel,
60 word: *const ::std::os::raw::c_char,
61 ) -> ::std::os::raw::c_int;
62
63 #[doc = " Loads speaker model data from the file and returns the model object"]
64 #[doc = ""]
65 #[doc = " @param model_path: the path of the model on the filesystem"]
66 #[doc = " @returns model object or NULL if problem occured"]
67 pub fn vosk_spk_model_new(model_path: *const ::std::os::raw::c_char) -> *mut VoskSpkModel;
68
69 #[doc = " Releases the model memory"]
70 #[doc = ""]
71 #[doc = " The model object is reference-counted so if some recognizer"]
72 #[doc = " depends on this model, model might still stay alive. When"]
73 #[doc = " last recognizer is released, model will be released too."]
74 pub fn vosk_spk_model_free(model: *mut VoskSpkModel);
75
76 #[doc = " Creates the recognizer object"]
77 #[doc = ""]
78 #[doc = " The recognizers process the speech and return text using shared model data"]
79 #[doc = " @param model VoskModel containing static data for recognizer. Model can be"]
80 #[doc = " shared across recognizers, even running in different threads."]
81 #[doc = " @param sample_rate The sample rate of the audio you going to feed into the recognizer."]
82 #[doc = " Make sure this rate matches the audio content, it is a common"]
83 #[doc = " issue causing accuracy problems."]
84 #[doc = " @returns recognizer object or NULL if problem occured"]
85 pub fn vosk_recognizer_new(model: *mut VoskModel, sample_rate: f32) -> *mut VoskRecognizer;
86
87 #[doc = " Creates the recognizer object with speaker recognition"]
88 #[doc = ""]
89 #[doc = " With the speaker recognition mode the recognizer not just recognize"]
90 #[doc = " text but also return speaker vectors one can use for speaker identification"]
91 #[doc = ""]
92 #[doc = " @param model VoskModel containing static data for recognizer. Model can be"]
93 #[doc = " shared across recognizers, even running in different threads."]
94 #[doc = " @param sample_rate The sample rate of the audio you going to feed into the recognizer."]
95 #[doc = " Make sure this rate matches the audio content, it is a common"]
96 #[doc = " issue causing accuracy problems."]
97 #[doc = " @param spk_model speaker model for speaker identification"]
98 #[doc = " @returns recognizer object or NULL if problem occured"]
99 pub fn vosk_recognizer_new_spk(
100 model: *mut VoskModel,
101 sample_rate: f32,
102 spk_model: *mut VoskSpkModel,
103 ) -> *mut VoskRecognizer;
104
105 #[doc = " Creates the recognizer object with the phrase list"]
106 #[doc = ""]
107 #[doc = " Sometimes when you want to improve recognition accuracy and when you don't need"]
108 #[doc = " to recognize large vocabulary you can specify a list of phrases to recognize. This"]
109 #[doc = " will improve recognizer speed and accuracy but might return \\[unk\\] if user said"]
110 #[doc = " something different."]
111 #[doc = ""]
112 #[doc = " Only recognizers with lookahead models support this type of quick configuration."]
113 #[doc = " Precompiled HCLG graph models are not supported."]
114 #[doc = ""]
115 #[doc = " @param model VoskModel containing static data for recognizer. Model can be"]
116 #[doc = " shared across recognizers, even running in different threads."]
117 #[doc = " @param sample_rate The sample rate of the audio you going to feed into the recognizer."]
118 #[doc = " Make sure this rate matches the audio content, it is a common"]
119 #[doc = " issue causing accuracy problems."]
120 #[doc = " @param grammar The string with the list of phrases to recognize as JSON array of strings,"]
121 #[doc = " for example \"\\[\"one two three four five\", \"\\[unk\\]\"\\]\"."]
122 #[doc = ""]
123 #[doc = " @returns recognizer object or NULL if problem occured"]
124 pub fn vosk_recognizer_new_grm(
125 model: *mut VoskModel,
126 sample_rate: f32,
127 grammar: *const ::std::os::raw::c_char,
128 ) -> *mut VoskRecognizer;
129
130 #[doc = " Adds speaker model to already initialized recognizer"]
131 #[doc = ""]
132 #[doc = " Can add speaker recognition model to already created recognizer. Helps to initialize"]
133 #[doc = " speaker recognition for grammar-based recognizer."]
134 #[doc = ""]
135 #[doc = " @param spk_model Speaker recognition model"]
136 pub fn vosk_recognizer_set_spk_model(
137 recognizer: *mut VoskRecognizer,
138 spk_model: *mut VoskSpkModel,
139 );
140
141 #[doc = " Configures recognizer to output n-best results"]
142 #[doc = ""]
143 #[doc = " <pre>"]
144 #[doc = " {"]
145 #[doc = " \"alternatives\": ["]
146 #[doc = " { \"text\": \"one two three four five\", \"confidence\": 0.97 },"]
147 #[doc = " { \"text\": \"one two three for five\", \"confidence\": 0.03 },"]
148 #[doc = " ]"]
149 #[doc = " }"]
150 #[doc = " </pre>"]
151 #[doc = ""]
152 #[doc = " @param max_alternatives - maximum alternatives to return from recognition results"]
153 pub fn vosk_recognizer_set_max_alternatives(
154 recognizer: *mut VoskRecognizer,
155 max_alternatives: ::std::os::raw::c_int,
156 );
157
158 #[doc = " Enables words with times in the output"]
159 #[doc = ""]
160 #[doc = " <pre>"]
161 #[doc = " \"result\" : [{"]
162 #[doc = " \"conf\" : 1.000000,"]
163 #[doc = " \"end\" : 1.110000,"]
164 #[doc = " \"start\" : 0.870000,"]
165 #[doc = " \"word\" : \"what\""]
166 #[doc = " }, {"]
167 #[doc = " \"conf\" : 1.000000,"]
168 #[doc = " \"end\" : 1.530000,"]
169 #[doc = " \"start\" : 1.110000,"]
170 #[doc = " \"word\" : \"zero\""]
171 #[doc = " }, {"]
172 #[doc = " \"conf\" : 1.000000,"]
173 #[doc = " \"end\" : 1.950000,"]
174 #[doc = " \"start\" : 1.530000,"]
175 #[doc = " \"word\" : \"zero\""]
176 #[doc = " }, {"]
177 #[doc = " \"conf\" : 1.000000,"]
178 #[doc = " \"end\" : 2.340000,"]
179 #[doc = " \"start\" : 1.950000,"]
180 #[doc = " \"word\" : \"zero\""]
181 #[doc = " }, {"]
182 #[doc = " \"conf\" : 1.000000,"]
183 #[doc = " \"end\" : 2.610000,"]
184 #[doc = " \"start\" : 2.340000,"]
185 #[doc = " \"word\" : \"one\""]
186 #[doc = " }],"]
187 #[doc = " </pre>"]
188 #[doc = ""]
189 #[doc = " @param words - boolean value"]
190 pub fn vosk_recognizer_set_words(recognizer: *mut VoskRecognizer, words: ::std::os::raw::c_int);
191
192 #[doc = " Like above return words and confidences in partial results"]
193 #[doc = ""]
194 #[doc = " @param partial_words - boolean value"]
195 pub fn vosk_recognizer_set_partial_words(
196 recognizer: *mut VoskRecognizer,
197 partial_words: ::std::os::raw::c_int,
198 );
199
200 #[doc = " Set NLSML output"]
201 #[doc = " @param nlsml - boolean value"]
202 pub fn vosk_recognizer_set_nlsml(recognizer: *mut VoskRecognizer, nlsml: ::std::os::raw::c_int);
203
204 #[doc = " Accept voice data"]
205 #[doc = ""]
206 #[doc = " accept and process new chunk of voice data"]
207 #[doc = ""]
208 #[doc = " @param data - audio data in PCM 16-bit mono format"]
209 #[doc = " @param length - length of the audio data"]
210 #[doc = " @returns 1 if silence is occured and you can retrieve a new utterance with result method"]
211 #[doc = " 0 if decoding continues"]
212 #[doc = " -1 if exception occured"]
213 pub fn vosk_recognizer_accept_waveform(
214 recognizer: *mut VoskRecognizer,
215 data: *const ::std::os::raw::c_char,
216 length: ::std::os::raw::c_int,
217 ) -> ::std::os::raw::c_int;
218
219 #[doc = " Same as above but the version with the short data for language bindings where you have"]
220 #[doc = " audio as array of shorts"]
221 pub fn vosk_recognizer_accept_waveform_s(
222 recognizer: *mut VoskRecognizer,
223 data: *const ::std::os::raw::c_short,
224 length: ::std::os::raw::c_int,
225 ) -> ::std::os::raw::c_int;
226
227 #[doc = " Same as above but the version with the float data for language bindings where you have"]
228 #[doc = " audio as array of floats"]
229 pub fn vosk_recognizer_accept_waveform_f(
230 recognizer: *mut VoskRecognizer,
231 data: *const f32,
232 length: ::std::os::raw::c_int,
233 ) -> ::std::os::raw::c_int;
234
235 #[doc = " Returns speech recognition result"]
236 #[doc = ""]
237 #[doc = " @returns the result in JSON format which contains decoded line, decoded"]
238 #[doc = " words, times in seconds and confidences. You can parse this result"]
239 #[doc = " with any json parser"]
240 #[doc = ""]
241 #[doc = " <pre>"]
242 #[doc = " {"]
243 #[doc = " \"text\" : \"what zero zero zero one\""]
244 #[doc = " }"]
245 #[doc = " </pre>"]
246 #[doc = ""]
247 #[doc = " If alternatives enabled it returns result with alternatives, see also vosk_recognizer_set_alternatives()."]
248 #[doc = ""]
249 #[doc = " If word times enabled returns word time, see also vosk_recognizer_set_word_times()."]
250 pub fn vosk_recognizer_result(recognizer: *mut VoskRecognizer)
251 -> *const ::std::os::raw::c_char;
252
253 #[doc = " Returns partial speech recognition"]
254 #[doc = ""]
255 #[doc = " @returns partial speech recognition text which is not yet finalized."]
256 #[doc = " result may change as recognizer process more data."]
257 #[doc = ""]
258 #[doc = " <pre>"]
259 #[doc = " {"]
260 #[doc = " \"partial\" : \"cyril one eight zero\""]
261 #[doc = " }"]
262 #[doc = " </pre>"]
263 pub fn vosk_recognizer_partial_result(
264 recognizer: *mut VoskRecognizer,
265 ) -> *const ::std::os::raw::c_char;
266
267 #[doc = " Returns speech recognition result. Same as result, but doesn't wait for silence"]
268 #[doc = " You usually call it in the end of the stream to get final bits of audio. It"]
269 #[doc = " flushes the feature pipeline, so all remaining audio chunks got processed."]
270 #[doc = ""]
271 #[doc = " @returns speech result in JSON format."]
272 pub fn vosk_recognizer_final_result(
273 recognizer: *mut VoskRecognizer,
274 ) -> *const ::std::os::raw::c_char;
275
276 #[doc = " Resets the recognizer"]
277 #[doc = ""]
278 #[doc = " Resets current results so the recognition can continue from scratch"]
279 pub fn vosk_recognizer_reset(recognizer: *mut VoskRecognizer);
280
281 #[doc = " Releases recognizer object"]
282 #[doc = ""]
283 #[doc = " Underlying model is also unreferenced and if needed released"]
284 pub fn vosk_recognizer_free(recognizer: *mut VoskRecognizer);
285
286 #[doc = " Set log level for Kaldi messages"]
287 #[doc = ""]
288 #[doc = " @param log_level the level"]
289 #[doc = " 0 - default value to print info and error messages but no debug"]
290 #[doc = " less than 0 - don't print info messages"]
291 #[doc = " greather than 0 - more verbose mode"]
292 pub fn vosk_set_log_level(log_level: ::std::os::raw::c_int);
293
294 #[doc = " Init, automatically select a CUDA device and allow multithreading."]
295 #[doc = " Must be called once from the main thread."]
296 #[doc = " Has no effect if HAVE_CUDA flag is not set."]
297 pub fn vosk_gpu_init();
298
299 #[doc = " Init CUDA device in a multi-threaded environment."]
300 #[doc = " Must be called for each thread."]
301 #[doc = " Has no effect if HAVE_CUDA flag is not set."]
302 pub fn vosk_gpu_thread_init();
303
304 #[doc = " Creates the batch recognizer object"]
305 #[doc = ""]
306 #[doc = " @returns model object or NULL if problem occured"]
307 pub fn vosk_batch_model_new(model_path: *const ::std::os::raw::c_char) -> *mut VoskBatchModel;
308
309 #[doc = " Releases batch model object"]
310 pub fn vosk_batch_model_free(model: *mut VoskBatchModel);
311
312 #[doc = " Wait for the processing"]
313 pub fn vosk_batch_model_wait(model: *mut VoskBatchModel);
314
315 #[doc = " Creates batch recognizer object"]
316 #[doc = " @returns recognizer object or NULL if problem occured"]
317 pub fn vosk_batch_recognizer_new(
318 model: *mut VoskBatchModel,
319 sample_rate: f32,
320 ) -> *mut VoskBatchRecognizer;
321
322 #[doc = " Releases batch recognizer object"]
323 pub fn vosk_batch_recognizer_free(recognizer: *mut VoskBatchRecognizer);
324
325 #[doc = " Accept batch voice data"]
326 pub fn vosk_batch_recognizer_accept_waveform(
327 recognizer: *mut VoskBatchRecognizer,
328 data: *const ::std::os::raw::c_char,
329 length: ::std::os::raw::c_int,
330 );
331
332 #[doc = " Set NLSML output"]
333 #[doc = " @param nlsml - boolean value"]
334 pub fn vosk_batch_recognizer_set_nlsml(
335 recognizer: *mut VoskBatchRecognizer,
336 nlsml: ::std::os::raw::c_int,
337 );
338
339 #[doc = " Closes the stream"]
340 pub fn vosk_batch_recognizer_finish_stream(recognizer: *mut VoskBatchRecognizer);
341
342 #[doc = " Return results"]
343 pub fn vosk_batch_recognizer_front_result(
344 recognizer: *mut VoskBatchRecognizer,
345 ) -> *const ::std::os::raw::c_char;
346
347 #[doc = " Release and free first retrieved result"]
348 pub fn vosk_batch_recognizer_pop(recognizer: *mut VoskBatchRecognizer);
349
350 #[doc = " Get amount of pending chunks for more intelligent waiting"]
351 pub fn vosk_batch_recognizer_get_pending_chunks(
352 recognizer: *mut VoskBatchRecognizer,
353 ) -> ::std::os::raw::c_int;
354}