Committed by
GitHub
OfflineRecognizer supports create stream with hotwords (#1833)
Co-authored-by: Wangkai <kell.wang@huawei.com>
正在显示
4 个修改的文件
包含
26 行增加
和
2 行删除
| @@ -533,6 +533,13 @@ const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream( | @@ -533,6 +533,13 @@ const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream( | ||
| 533 | return stream; | 533 | return stream; |
| 534 | } | 534 | } |
| 535 | 535 | ||
| 536 | +const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStreamWithHotwords( | ||
| 537 | + const SherpaOnnxOfflineRecognizer *recognizer, const char *hotwords) { | ||
| 538 | + SherpaOnnxOfflineStream *stream = | ||
| 539 | + new SherpaOnnxOfflineStream(recognizer->impl->CreateStream(hotwords)); | ||
| 540 | + return stream; | ||
| 541 | +} | ||
| 542 | + | ||
| 536 | void SherpaOnnxDestroyOfflineStream(const SherpaOnnxOfflineStream *stream) { | 543 | void SherpaOnnxDestroyOfflineStream(const SherpaOnnxOfflineStream *stream) { |
| 537 | delete stream; | 544 | delete stream; |
| 538 | } | 545 | } |
| @@ -484,6 +484,16 @@ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineRecognizer( | @@ -484,6 +484,16 @@ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineRecognizer( | ||
| 484 | SHERPA_ONNX_API const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream( | 484 | SHERPA_ONNX_API const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream( |
| 485 | const SherpaOnnxOfflineRecognizer *recognizer); | 485 | const SherpaOnnxOfflineRecognizer *recognizer); |
| 486 | 486 | ||
| 487 | +/// Create an offline stream for accepting wave samples with the specified hot | ||
| 488 | +/// words. | ||
| 489 | +/// | ||
| 490 | +/// @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer() | ||
| 491 | +/// @return Return a pointer to an OfflineStream. The user has to invoke | ||
| 492 | +/// SherpaOnnxDestroyOfflineStream() to free it to avoid memory leak. | ||
| 493 | +SHERPA_ONNX_API const SherpaOnnxOfflineStream * | ||
| 494 | +SherpaOnnxCreateOfflineStreamWithHotwords( | ||
| 495 | + const SherpaOnnxOfflineRecognizer *recognizer, const char *hotwords); | ||
| 496 | + | ||
| 487 | /// Destroy an offline stream. | 497 | /// Destroy an offline stream. |
| 488 | /// | 498 | /// |
| 489 | /// @param stream A pointer returned by SherpaOnnxCreateOfflineStream() | 499 | /// @param stream A pointer returned by SherpaOnnxCreateOfflineStream() |
| @@ -266,8 +266,13 @@ void OfflineRecognizer::Destroy(const SherpaOnnxOfflineRecognizer *p) const { | @@ -266,8 +266,13 @@ void OfflineRecognizer::Destroy(const SherpaOnnxOfflineRecognizer *p) const { | ||
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | OfflineStream OfflineRecognizer::CreateStream() const { | 268 | OfflineStream OfflineRecognizer::CreateStream() const { |
| 269 | - auto p = SherpaOnnxCreateOfflineStream(p_); | ||
| 270 | - return OfflineStream{p}; | 269 | + auto s = SherpaOnnxCreateOfflineStream(p_); |
| 270 | + return OfflineStream{s}; | ||
| 271 | +} | ||
| 272 | + | ||
| 273 | +OfflineStream OfflineRecognizer::CreateStream(const std::string &hotwords) const { | ||
| 274 | + auto s = SherpaOnnxCreateOfflineStreamWithHotwords(p_, hotwords.c_str()); | ||
| 275 | + return OfflineStream{s}; | ||
| 271 | } | 276 | } |
| 272 | 277 | ||
| 273 | void OfflineRecognizer::Decode(const OfflineStream *s) const { | 278 | void OfflineRecognizer::Decode(const OfflineStream *s) const { |
| @@ -301,6 +301,8 @@ class SHERPA_ONNX_API OfflineRecognizer | @@ -301,6 +301,8 @@ class SHERPA_ONNX_API OfflineRecognizer | ||
| 301 | 301 | ||
| 302 | OfflineStream CreateStream() const; | 302 | OfflineStream CreateStream() const; |
| 303 | 303 | ||
| 304 | + OfflineStream CreateStream(const std::string &hotwords) const; | ||
| 305 | + | ||
| 304 | void Decode(const OfflineStream *s) const; | 306 | void Decode(const OfflineStream *s) const; |
| 305 | 307 | ||
| 306 | void Decode(const OfflineStream *ss, int32_t n) const; | 308 | void Decode(const OfflineStream *ss, int32_t n) const; |
-
请 注册 或 登录 后发表评论