Skip to content

Commit 2ac41d3

Browse files
kellkwangWangkai
and
Wangkai
authored
OfflineRecognizer supports create stream with hotwords (#1833)
Co-authored-by: Wangkai <kell.wang@huawei.com>
1 parent 9559a10 commit 2ac41d3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

sherpa-onnx/c-api/c-api.cc

+7
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream(
533533
return stream;
534534
}
535535

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+
536543
void SherpaOnnxDestroyOfflineStream(const SherpaOnnxOfflineStream *stream) {
537544
delete stream;
538545
}

sherpa-onnx/c-api/c-api.h

+10
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,16 @@ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineRecognizer(
484484
SHERPA_ONNX_API const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream(
485485
const SherpaOnnxOfflineRecognizer *recognizer);
486486

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+
487497
/// Destroy an offline stream.
488498
///
489499
/// @param stream A pointer returned by SherpaOnnxCreateOfflineStream()

sherpa-onnx/c-api/cxx-api.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,13 @@ void OfflineRecognizer::Destroy(const SherpaOnnxOfflineRecognizer *p) const {
266266
}
267267

268268
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};
271276
}
272277

273278
void OfflineRecognizer::Decode(const OfflineStream *s) const {

sherpa-onnx/c-api/cxx-api.h

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ class SHERPA_ONNX_API OfflineRecognizer
301301

302302
OfflineStream CreateStream() const;
303303

304+
OfflineStream CreateStream(const std::string &hotwords) const;
305+
304306
void Decode(const OfflineStream *s) const;
305307

306308
void Decode(const OfflineStream *ss, int32_t n) const;

0 commit comments

Comments
 (0)