11
11
12
12
#include " sherpa-onnx/csrc/circular-buffer.h"
13
13
#include " sherpa-onnx/csrc/display.h"
14
+ #include " sherpa-onnx/csrc/keyword-spotter.h"
14
15
#include " sherpa-onnx/csrc/macros.h"
15
16
#include " sherpa-onnx/csrc/offline-recognizer.h"
16
17
#include " sherpa-onnx/csrc/offline-tts.h"
17
18
#include " sherpa-onnx/csrc/online-recognizer.h"
18
19
#include " sherpa-onnx/csrc/voice-activity-detector.h"
19
20
#include " sherpa-onnx/csrc/wave-writer.h"
20
- #include " sherpa-onnx/csrc/keyword-spotter.h"
21
21
22
22
struct SherpaOnnxOnlineRecognizer {
23
23
std::unique_ptr<sherpa_onnx::OnlineRecognizer> impl;
@@ -301,6 +301,9 @@ SherpaOnnxOfflineRecognizer *CreateOfflineRecognizer(
301
301
recognizer_config.model_config .whisper .language =
302
302
SHERPA_ONNX_OR (config->model_config .whisper .language , " " );
303
303
304
+ recognizer_config.model_config .whisper .task =
305
+ SHERPA_ONNX_OR (config->model_config .whisper .task , " transcribe" );
306
+
304
307
recognizer_config.model_config .tdnn .model =
305
308
SHERPA_ONNX_OR (config->model_config .tdnn .model , " " );
306
309
@@ -422,8 +425,8 @@ struct SherpaOnnxKeywordSpotter {
422
425
std::unique_ptr<sherpa_onnx::KeywordSpotter> impl;
423
426
};
424
427
425
- SherpaOnnxKeywordSpotter* CreateKeywordSpotter (
426
- const SherpaOnnxKeywordSpotterConfig* config) {
428
+ SherpaOnnxKeywordSpotter * CreateKeywordSpotter (
429
+ const SherpaOnnxKeywordSpotterConfig * config) {
427
430
sherpa_onnx::KeywordSpotterConfig spotter_config;
428
431
429
432
spotter_config.feat_config .sampling_rate =
@@ -457,20 +460,17 @@ SherpaOnnxKeywordSpotter* CreateKeywordSpotter(
457
460
spotter_config.model_config .debug =
458
461
SHERPA_ONNX_OR (config->model_config .debug , 0 );
459
462
460
- spotter_config.max_active_paths =
461
- SHERPA_ONNX_OR (config->max_active_paths , 4 );
463
+ spotter_config.max_active_paths = SHERPA_ONNX_OR (config->max_active_paths , 4 );
462
464
463
465
spotter_config.num_trailing_blanks =
464
- SHERPA_ONNX_OR (config->num_trailing_blanks , 1 );
466
+ SHERPA_ONNX_OR (config->num_trailing_blanks , 1 );
465
467
466
- spotter_config.keywords_score =
467
- SHERPA_ONNX_OR (config->keywords_score , 1.0 );
468
+ spotter_config.keywords_score = SHERPA_ONNX_OR (config->keywords_score , 1.0 );
468
469
469
470
spotter_config.keywords_threshold =
470
471
SHERPA_ONNX_OR (config->keywords_threshold , 0.25 );
471
472
472
- spotter_config.keywords_file =
473
- SHERPA_ONNX_OR (config->keywords_file , " " );
473
+ spotter_config.keywords_file = SHERPA_ONNX_OR (config->keywords_file , " " );
474
474
475
475
if (config->model_config .debug ) {
476
476
SHERPA_ONNX_LOGE (" %s\n " , spotter_config.ToString ().c_str ());
@@ -481,39 +481,37 @@ SherpaOnnxKeywordSpotter* CreateKeywordSpotter(
481
481
return nullptr ;
482
482
}
483
483
484
- SherpaOnnxKeywordSpotter* spotter = new SherpaOnnxKeywordSpotter;
484
+ SherpaOnnxKeywordSpotter * spotter = new SherpaOnnxKeywordSpotter;
485
485
486
- spotter->impl =
487
- std::make_unique<sherpa_onnx::KeywordSpotter>(spotter_config);
486
+ spotter->impl = std::make_unique<sherpa_onnx::KeywordSpotter>(spotter_config);
488
487
489
488
return spotter;
490
489
}
491
490
492
- void DestroyKeywordSpotter (SherpaOnnxKeywordSpotter* spotter) {
491
+ void DestroyKeywordSpotter (SherpaOnnxKeywordSpotter * spotter) {
493
492
delete spotter;
494
493
}
495
494
496
- SherpaOnnxOnlineStream* CreateKeywordStream (
497
- const SherpaOnnxKeywordSpotter* spotter) {
498
- SherpaOnnxOnlineStream* stream =
495
+ SherpaOnnxOnlineStream * CreateKeywordStream (
496
+ const SherpaOnnxKeywordSpotter * spotter) {
497
+ SherpaOnnxOnlineStream * stream =
499
498
new SherpaOnnxOnlineStream (spotter->impl ->CreateStream ());
500
499
return stream;
501
500
}
502
501
503
- int32_t IsKeywordStreamReady (
504
- SherpaOnnxKeywordSpotter* spotter, SherpaOnnxOnlineStream* stream) {
502
+ int32_t IsKeywordStreamReady (SherpaOnnxKeywordSpotter *spotter,
503
+ SherpaOnnxOnlineStream * stream) {
505
504
return spotter->impl ->IsReady (stream->impl .get ());
506
505
}
507
506
508
- void DecodeKeywordStream (SherpaOnnxKeywordSpotter* spotter,
509
- SherpaOnnxOnlineStream* stream) {
507
+ void DecodeKeywordStream (SherpaOnnxKeywordSpotter * spotter,
508
+ SherpaOnnxOnlineStream * stream) {
510
509
return spotter->impl ->DecodeStream (stream->impl .get ());
511
510
}
512
511
513
- void DecodeMultipleKeywordStreams (
514
- SherpaOnnxKeywordSpotter *spotter, SherpaOnnxOnlineStream **streams,
515
- int32_t n) {
516
- std::vector<sherpa_onnx::OnlineStream*> ss (n);
512
+ void DecodeMultipleKeywordStreams (SherpaOnnxKeywordSpotter *spotter,
513
+ SherpaOnnxOnlineStream **streams, int32_t n) {
514
+ std::vector<sherpa_onnx::OnlineStream *> ss (n);
517
515
for (int32_t i = 0 ; i != n; ++i) {
518
516
ss[i] = streams[i]->impl .get ();
519
517
}
@@ -522,7 +520,7 @@ void DecodeMultipleKeywordStreams(
522
520
523
521
const SherpaOnnxKeywordResult *GetKeywordResult (
524
522
SherpaOnnxKeywordSpotter *spotter, SherpaOnnxOnlineStream *stream) {
525
- const sherpa_onnx::KeywordResult& result =
523
+ const sherpa_onnx::KeywordResult & result =
526
524
spotter->impl ->GetResult (stream->impl .get ());
527
525
const auto &keyword = result.keyword ;
528
526
0 commit comments