正在显示
2 个修改的文件
包含
46 行增加
和
0 行删除
| @@ -361,6 +361,35 @@ OfflineRecognizerResult OfflineRecognizer::GetResult( | @@ -361,6 +361,35 @@ OfflineRecognizerResult OfflineRecognizer::GetResult( | ||
| 361 | return ans; | 361 | return ans; |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | +std::shared_ptr<OfflineRecognizerResult> OfflineRecognizer::GetResultPtr(const OfflineStream *s) const | ||
| 365 | +{ | ||
| 366 | + auto r = SherpaOnnxGetOfflineStreamResult(s->Get()); | ||
| 367 | + | ||
| 368 | + OfflineRecognizerResult* ans = new OfflineRecognizerResult; | ||
| 369 | + if (r) { | ||
| 370 | + ans->text = r->text; | ||
| 371 | + | ||
| 372 | + if (r->timestamps) { | ||
| 373 | + ans->timestamps.resize(r->count); | ||
| 374 | + std::copy(r->timestamps, r->timestamps + r->count, ans->timestamps.data()); | ||
| 375 | + } | ||
| 376 | + | ||
| 377 | + ans->tokens.resize(r->count); | ||
| 378 | + for (int32_t i = 0; i != r->count; ++i) { | ||
| 379 | + ans->tokens[i] = r->tokens_arr[i]; | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + ans->json = r->json; | ||
| 383 | + ans->lang = r->lang ? r->lang : ""; | ||
| 384 | + ans->emotion = r->emotion ? r->emotion : ""; | ||
| 385 | + ans->event = r->event ? r->event : ""; | ||
| 386 | + } | ||
| 387 | + | ||
| 388 | + SherpaOnnxDestroyOfflineRecognizerResult(r); | ||
| 389 | + | ||
| 390 | + return std::shared_ptr<OfflineRecognizerResult>(ans); | ||
| 391 | +} | ||
| 392 | + | ||
| 364 | OfflineTts OfflineTts::Create(const OfflineTtsConfig &config) { | 393 | OfflineTts OfflineTts::Create(const OfflineTtsConfig &config) { |
| 365 | struct SherpaOnnxOfflineTtsConfig c; | 394 | struct SherpaOnnxOfflineTtsConfig c; |
| 366 | memset(&c, 0, sizeof(c)); | 395 | memset(&c, 0, sizeof(c)); |
| @@ -565,6 +594,7 @@ KeywordResult KeywordSpotter::GetResult(const OnlineStream *s) const { | @@ -565,6 +594,7 @@ KeywordResult KeywordSpotter::GetResult(const OnlineStream *s) const { | ||
| 565 | return ans; | 594 | return ans; |
| 566 | } | 595 | } |
| 567 | 596 | ||
| 597 | + | ||
| 568 | void KeywordSpotter::Reset(const OnlineStream *s) const { | 598 | void KeywordSpotter::Reset(const OnlineStream *s) const { |
| 569 | SherpaOnnxResetKeywordStream(p_, s->Get()); | 599 | SherpaOnnxResetKeywordStream(p_, s->Get()); |
| 570 | } | 600 | } |
| @@ -723,6 +753,18 @@ SpeechSegment VoiceActivityDetector::Front() const { | @@ -723,6 +753,18 @@ SpeechSegment VoiceActivityDetector::Front() const { | ||
| 723 | return segment; | 753 | return segment; |
| 724 | } | 754 | } |
| 725 | 755 | ||
| 756 | +std::shared_ptr<SpeechSegment> VoiceActivityDetector::FrontPtr() const | ||
| 757 | +{ | ||
| 758 | + auto f = SherpaOnnxVoiceActivityDetectorFront(p_); | ||
| 759 | + | ||
| 760 | + SpeechSegment* segment = new SpeechSegment; | ||
| 761 | + segment->start = f->start; | ||
| 762 | + segment->samples = std::vector<float>{f->samples, f->samples + f->n}; | ||
| 763 | + | ||
| 764 | + SherpaOnnxDestroySpeechSegment(f); | ||
| 765 | + return std::shared_ptr<SpeechSegment>(segment); | ||
| 766 | +} | ||
| 767 | + | ||
| 726 | void VoiceActivityDetector::Reset() const { | 768 | void VoiceActivityDetector::Reset() const { |
| 727 | SherpaOnnxVoiceActivityDetectorReset(p_); | 769 | SherpaOnnxVoiceActivityDetectorReset(p_); |
| 728 | } | 770 | } |
| @@ -349,6 +349,8 @@ class SHERPA_ONNX_API OfflineRecognizer | @@ -349,6 +349,8 @@ class SHERPA_ONNX_API OfflineRecognizer | ||
| 349 | 349 | ||
| 350 | OfflineRecognizerResult GetResult(const OfflineStream *s) const; | 350 | OfflineRecognizerResult GetResult(const OfflineStream *s) const; |
| 351 | 351 | ||
| 352 | + std::shared_ptr<OfflineRecognizerResult> GetResultPtr(const OfflineStream *s) const; | ||
| 353 | + | ||
| 352 | void SetConfig(const OfflineRecognizerConfig &config) const; | 354 | void SetConfig(const OfflineRecognizerConfig &config) const; |
| 353 | 355 | ||
| 354 | private: | 356 | private: |
| @@ -634,6 +636,8 @@ class SHERPA_ONNX_API VoiceActivityDetector | @@ -634,6 +636,8 @@ class SHERPA_ONNX_API VoiceActivityDetector | ||
| 634 | 636 | ||
| 635 | SpeechSegment Front() const; | 637 | SpeechSegment Front() const; |
| 636 | 638 | ||
| 639 | + std::shared_ptr<SpeechSegment> FrontPtr() const; | ||
| 640 | + | ||
| 637 | void Reset() const; | 641 | void Reset() const; |
| 638 | 642 | ||
| 639 | void Flush() const; | 643 | void Flush() const; |
-
请 注册 或 登录 后发表评论