Skip to content

Commit

Permalink
Add CreateOnlineStreamWithHotwords to C API (#323)
Browse files Browse the repository at this point in the history
* add default visibility to SHERPA_ONNX_EXPORT

* expose CreateOnlineStreamWithHotwords method via C API

Co-authored-by: Nick Fisher <[email protected]>
  • Loading branch information
nmfisher and Nick Fisher authored Sep 19, 2023
1 parent d7eab95 commit b3e9986
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sherpa-onnx/c-api/c-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ SherpaOnnxOnlineStream *CreateOnlineStream(
return stream;
}

SherpaOnnxOnlineStream *CreateOnlineStreamWithHotwords(
const SherpaOnnxOnlineRecognizer *recognizer, const char *hotwords) {
SherpaOnnxOnlineStream *stream =
new SherpaOnnxOnlineStream(recognizer->impl->CreateStream(hotwords));
return stream;
}

void DestroyOnlineStream(SherpaOnnxOnlineStream *stream) { delete stream; }

void AcceptWaveform(SherpaOnnxOnlineStream *stream, int32_t sample_rate,
Expand Down
9 changes: 8 additions & 1 deletion sherpa-onnx/c-api/c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern "C" {
#define SHERPA_ONNX_IMPORT
#endif
#else // WIN32
#define SHERPA_ONNX_EXPORT
#define SHERPA_ONNX_EXPORT __attribute__((visibility("default")))
#define SHERPA_ONNX_IMPORT SHERPA_ONNX_EXPORT
#endif

Expand Down Expand Up @@ -178,6 +178,13 @@ SHERPA_ONNX_API void DestroyOnlineRecognizer(
SHERPA_ONNX_API SherpaOnnxOnlineStream *CreateOnlineStream(
const SherpaOnnxOnlineRecognizer *recognizer);

/// Create an online stream for accepting wave samples with the specified hot words.
///
/// @param recognizer A pointer returned by CreateOnlineRecognizer()
/// @return Return a pointer to an OnlineStream. The user has to invoke
/// DestroyOnlineStream() to free it to avoid memory leak.
SHERPA_ONNX_API SherpaOnnxOnlineStream *CreateOnlineStreamWithHotwords(const SherpaOnnxOnlineRecognizer *recognizer, const char *hotwords);

/// Destroy an online stream.
///
/// @param stream A pointer returned by CreateOnlineStream()
Expand Down

0 comments on commit b3e9986

Please sign in to comment.