return timestamps for WebAssembly (#737)
This commit is contained in:
@@ -243,6 +243,20 @@ void DestroyOnlineRecognizerResult(const SherpaOnnxOnlineRecognizerResult *r) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *GetOnlineStreamResultAsJson(
|
||||
const SherpaOnnxOnlineRecognizer *recognizer,
|
||||
const SherpaOnnxOnlineStream *stream) {
|
||||
sherpa_onnx::OnlineRecognizerResult result =
|
||||
recognizer->impl->GetResult(stream->impl.get());
|
||||
std::string json = result.AsJsonString();
|
||||
char *pJson = new char[json.size() + 1];
|
||||
std::copy(json.begin(), json.end(), pJson);
|
||||
pJson[json.size()] = 0;
|
||||
return pJson;
|
||||
}
|
||||
|
||||
void DestroyOnlineStreamResultJson(const char *s) { delete[] s; }
|
||||
|
||||
void Reset(const SherpaOnnxOnlineRecognizer *recognizer,
|
||||
const SherpaOnnxOnlineStream *stream) {
|
||||
recognizer->impl->Reset(stream->impl.get());
|
||||
@@ -409,7 +423,7 @@ void DecodeMultipleOfflineStreams(SherpaOnnxOfflineRecognizer *recognizer,
|
||||
}
|
||||
|
||||
const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
||||
SherpaOnnxOfflineStream *stream) {
|
||||
const SherpaOnnxOfflineStream *stream) {
|
||||
const sherpa_onnx::OfflineRecognitionResult &result =
|
||||
stream->impl->GetResult();
|
||||
const auto &text = result.text;
|
||||
@@ -444,6 +458,19 @@ void DestroyOfflineRecognizerResult(
|
||||
}
|
||||
}
|
||||
|
||||
const char *GetOfflineStreamResultAsJson(
|
||||
const SherpaOnnxOfflineStream *stream) {
|
||||
const sherpa_onnx::OfflineRecognitionResult &result =
|
||||
stream->impl->GetResult();
|
||||
std::string json = result.AsJsonString();
|
||||
char *pJson = new char[json.size() + 1];
|
||||
std::copy(json.begin(), json.end(), pJson);
|
||||
pJson[json.size()] = 0;
|
||||
return pJson;
|
||||
}
|
||||
|
||||
void DestroyOfflineStreamResultJson(const char *s) { delete[] s; }
|
||||
|
||||
// ============================================================
|
||||
// For Keyword Spot
|
||||
// ============================================================
|
||||
|
||||
@@ -286,6 +286,16 @@ SHERPA_ONNX_API const SherpaOnnxOnlineRecognizerResult *GetOnlineStreamResult(
|
||||
SHERPA_ONNX_API void DestroyOnlineRecognizerResult(
|
||||
const SherpaOnnxOnlineRecognizerResult *r);
|
||||
|
||||
/// Return the result as a json string.
|
||||
/// The user has to invoke
|
||||
/// DestroyOnlineStreamResultJson()
|
||||
/// to free the returned pointer to avoid memory leak
|
||||
SHERPA_ONNX_API const char *GetOnlineStreamResultAsJson(
|
||||
const SherpaOnnxOnlineRecognizer *recognizer,
|
||||
const SherpaOnnxOnlineStream *stream);
|
||||
|
||||
SHERPA_ONNX_API void DestroyOnlineStreamResultJson(const char *s);
|
||||
|
||||
/// Reset an OnlineStream , which clears the neural network model state
|
||||
/// and the state for decoding.
|
||||
///
|
||||
@@ -482,7 +492,7 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizerResult {
|
||||
/// DestroyOnlineRecognizerResult() to free the returned pointer to
|
||||
/// avoid memory leak.
|
||||
SHERPA_ONNX_API const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
||||
SherpaOnnxOfflineStream *stream);
|
||||
const SherpaOnnxOfflineStream *stream);
|
||||
|
||||
/// Destroy the pointer returned by GetOfflineStreamResult().
|
||||
///
|
||||
@@ -490,6 +500,14 @@ SHERPA_ONNX_API const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
||||
SHERPA_ONNX_API void DestroyOfflineRecognizerResult(
|
||||
const SherpaOnnxOfflineRecognizerResult *r);
|
||||
|
||||
/// Return the result as a json string.
|
||||
/// The user has to use DestroyOfflineStreamResultJson()
|
||||
/// to free the returned pointer to avoid memory leak
|
||||
SHERPA_ONNX_API const char *GetOfflineStreamResultAsJson(
|
||||
const SherpaOnnxOfflineStream *stream);
|
||||
|
||||
SHERPA_ONNX_API void DestroyOfflineStreamResultJson(const char *s);
|
||||
|
||||
// ============================================================
|
||||
// For Keyword Spot
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user