return timestamps for WebAssembly (#737)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
project(sherpa-onnx)
|
project(sherpa-onnx)
|
||||||
|
|
||||||
set(SHERPA_ONNX_VERSION "1.9.15")
|
set(SHERPA_ONNX_VERSION "1.9.16")
|
||||||
|
|
||||||
# Disable warning about
|
# Disable warning about
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ cmake \
|
|||||||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
||||||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
||||||
-DSHERPA_ONNX_ENABLE_JNI=OFF \
|
-DSHERPA_ONNX_ENABLE_JNI=OFF \
|
||||||
-DSHERPA_ONNX_ENABLE_C_API=OFF \
|
-DSHERPA_ONNX_ENABLE_C_API=ON \
|
||||||
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
|
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
|
||||||
-DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake \
|
||||||
..
|
..
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ cmake \
|
|||||||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
||||||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
||||||
-DSHERPA_ONNX_ENABLE_JNI=OFF \
|
-DSHERPA_ONNX_ENABLE_JNI=OFF \
|
||||||
-DSHERPA_ONNX_ENABLE_C_API=OFF \
|
-DSHERPA_ONNX_ENABLE_C_API=ON \
|
||||||
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
|
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
|
||||||
-DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake \
|
||||||
..
|
..
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ cmake \
|
|||||||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
|
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
|
||||||
-DSHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY=OFF \
|
-DSHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY=OFF \
|
||||||
..
|
..
|
||||||
make -j10
|
make -j3
|
||||||
make install
|
make install
|
||||||
|
|
||||||
ls -lh install/bin/wasm/nodejs
|
ls -lh install/bin/wasm/nodejs
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ fs.createReadStream(waveFilename, {highWaterMark: 4096})
|
|||||||
|
|
||||||
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
|
|
||||||
stream.free();
|
stream.free();
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ fs.createReadStream(waveFilename, {'highWaterMark': 4096})
|
|||||||
|
|
||||||
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
|
|
||||||
stream.free();
|
stream.free();
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ fs.createReadStream(waveFilename, {'highWaterMark': 4096})
|
|||||||
|
|
||||||
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
|
|
||||||
stream.free();
|
stream.free();
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ fs.createReadStream(waveFilename, {'highWaterMark': 4096})
|
|||||||
|
|
||||||
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
stream.acceptWaveform(recognizer.config.featConfig.sampleRate, flattened);
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
|
|
||||||
stream.free();
|
stream.free();
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ ai.on('data', data => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isEndpoint = recognizer.isEndpoint(stream);
|
const isEndpoint = recognizer.isEndpoint(stream);
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
|
|
||||||
if (text.length > 0 && lastText != text) {
|
if (text.length > 0 && lastText != text) {
|
||||||
lastText = text;
|
lastText = text;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ function decode(samples) {
|
|||||||
while (recognizer.isReady(stream)) {
|
while (recognizer.isReady(stream)) {
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
}
|
}
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ ai.on('data', data => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isEndpoint = recognizer.isEndpoint(stream);
|
const isEndpoint = recognizer.isEndpoint(stream);
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
|
|
||||||
if (text.length > 0 && lastText != text) {
|
if (text.length > 0 && lastText != text) {
|
||||||
lastText = text;
|
lastText = text;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ function decode(samples) {
|
|||||||
while (recognizer.isReady(stream)) {
|
while (recognizer.isReady(stream)) {
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
}
|
}
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ function decode(samples) {
|
|||||||
while (recognizer.isReady(stream)) {
|
while (recognizer.isReady(stream)) {
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
}
|
}
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ function decode(samples) {
|
|||||||
while (recognizer.isReady(stream)) {
|
while (recognizer.isReady(stream)) {
|
||||||
recognizer.decode(stream);
|
recognizer.decode(stream);
|
||||||
}
|
}
|
||||||
const text = recognizer.getResult(stream);
|
const text = recognizer.getResult(stream).text;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
void Reset(const SherpaOnnxOnlineRecognizer *recognizer,
|
||||||
const SherpaOnnxOnlineStream *stream) {
|
const SherpaOnnxOnlineStream *stream) {
|
||||||
recognizer->impl->Reset(stream->impl.get());
|
recognizer->impl->Reset(stream->impl.get());
|
||||||
@@ -409,7 +423,7 @@ void DecodeMultipleOfflineStreams(SherpaOnnxOfflineRecognizer *recognizer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
||||||
SherpaOnnxOfflineStream *stream) {
|
const SherpaOnnxOfflineStream *stream) {
|
||||||
const sherpa_onnx::OfflineRecognitionResult &result =
|
const sherpa_onnx::OfflineRecognitionResult &result =
|
||||||
stream->impl->GetResult();
|
stream->impl->GetResult();
|
||||||
const auto &text = result.text;
|
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
|
// For Keyword Spot
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
@@ -286,6 +286,16 @@ SHERPA_ONNX_API const SherpaOnnxOnlineRecognizerResult *GetOnlineStreamResult(
|
|||||||
SHERPA_ONNX_API void DestroyOnlineRecognizerResult(
|
SHERPA_ONNX_API void DestroyOnlineRecognizerResult(
|
||||||
const SherpaOnnxOnlineRecognizerResult *r);
|
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
|
/// Reset an OnlineStream , which clears the neural network model state
|
||||||
/// and the state for decoding.
|
/// and the state for decoding.
|
||||||
///
|
///
|
||||||
@@ -482,7 +492,7 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizerResult {
|
|||||||
/// DestroyOnlineRecognizerResult() to free the returned pointer to
|
/// DestroyOnlineRecognizerResult() to free the returned pointer to
|
||||||
/// avoid memory leak.
|
/// avoid memory leak.
|
||||||
SHERPA_ONNX_API const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
SHERPA_ONNX_API const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
||||||
SherpaOnnxOfflineStream *stream);
|
const SherpaOnnxOfflineStream *stream);
|
||||||
|
|
||||||
/// Destroy the pointer returned by GetOfflineStreamResult().
|
/// Destroy the pointer returned by GetOfflineStreamResult().
|
||||||
///
|
///
|
||||||
@@ -490,6 +500,14 @@ SHERPA_ONNX_API const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
|
|||||||
SHERPA_ONNX_API void DestroyOfflineRecognizerResult(
|
SHERPA_ONNX_API void DestroyOfflineRecognizerResult(
|
||||||
const SherpaOnnxOfflineRecognizerResult *r);
|
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
|
// For Keyword Spot
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
@@ -13,10 +13,14 @@ set(exported_functions
|
|||||||
CreateOnlineRecognizer
|
CreateOnlineRecognizer
|
||||||
CreateOnlineStream
|
CreateOnlineStream
|
||||||
DecodeOnlineStream
|
DecodeOnlineStream
|
||||||
|
DestroyOfflineStreamResultJson
|
||||||
DestroyOnlineRecognizer
|
DestroyOnlineRecognizer
|
||||||
DestroyOnlineRecognizerResult
|
DestroyOnlineRecognizerResult
|
||||||
DestroyOnlineStream
|
DestroyOnlineStream
|
||||||
|
DestroyOnlineStreamResultJson
|
||||||
|
GetOfflineStreamResultAsJson
|
||||||
GetOnlineStreamResult
|
GetOnlineStreamResult
|
||||||
|
GetOnlineStreamResultAsJson
|
||||||
InputFinished
|
InputFinished
|
||||||
IsEndpoint
|
IsEndpoint
|
||||||
IsOnlineStreamReady
|
IsOnlineStreamReady
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ if (navigator.mediaDevices.getUserMedia) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
||||||
let result = recognizer.getResult(recognizer_stream);
|
let result = recognizer.getResult(recognizer_stream).text;
|
||||||
|
|
||||||
|
|
||||||
if (result.length > 0 && lastResult != result) {
|
if (result.length > 0 && lastResult != result) {
|
||||||
|
|||||||
@@ -661,13 +661,12 @@ class OfflineRecognizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getResult(stream) {
|
getResult(stream) {
|
||||||
const r = this.Module._GetOfflineStreamResult(stream.handle);
|
const r = this.Module._GetOfflineStreamResultAsJson(stream.handle);
|
||||||
|
const jsonStr = this.Module.UTF8ToString(r);
|
||||||
|
const ans = JSON.parse(jsonStr);
|
||||||
|
this.Module._DestroyOfflineStreamResultJson(r);
|
||||||
|
|
||||||
const textPtr = this.Module.getValue(r, 'i8*');
|
return ans;
|
||||||
const text = this.Module.UTF8ToString(textPtr);
|
|
||||||
|
|
||||||
this.Module._DestroyOfflineRecognizerResult(r);
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -750,11 +749,13 @@ class OnlineRecognizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getResult(stream) {
|
getResult(stream) {
|
||||||
const r = this.Module._GetOnlineStreamResult(this.handle, stream.handle);
|
const r =
|
||||||
const textPtr = this.Module.getValue(r, 'i8*');
|
this.Module._GetOnlineStreamResultAsJson(this.handle, stream.handle);
|
||||||
const text = this.Module.UTF8ToString(textPtr);
|
const jsonStr = this.Module.UTF8ToString(r);
|
||||||
this.Module._DestroyOnlineRecognizerResult(r);
|
const ans = JSON.parse(jsonStr);
|
||||||
return text;
|
this.Module._DestroyOnlineStreamResultJson(r);
|
||||||
|
|
||||||
|
return ans;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,22 +21,26 @@ set(exported_functions
|
|||||||
DestroyOnlineRecognizer
|
DestroyOnlineRecognizer
|
||||||
DestroyOnlineRecognizerResult
|
DestroyOnlineRecognizerResult
|
||||||
DestroyOnlineStream
|
DestroyOnlineStream
|
||||||
|
DestroyOnlineStreamResultJson
|
||||||
GetOnlineStreamResult
|
GetOnlineStreamResult
|
||||||
|
GetOnlineStreamResultAsJson
|
||||||
InputFinished
|
InputFinished
|
||||||
IsEndpoint
|
IsEndpoint
|
||||||
IsOnlineStreamReady
|
IsOnlineStreamReady
|
||||||
Reset
|
Reset
|
||||||
# non-streaming ASR
|
# non-streaming ASR
|
||||||
PrintOfflineRecognizerConfig
|
|
||||||
CreateOfflineRecognizer
|
|
||||||
DestroyOfflineRecognizer
|
|
||||||
CreateOfflineStream
|
|
||||||
DestroyOfflineStream
|
|
||||||
AcceptWaveformOffline
|
AcceptWaveformOffline
|
||||||
DecodeOfflineStream
|
CreateOfflineRecognizer
|
||||||
|
CreateOfflineStream
|
||||||
DecodeMultipleOfflineStreams
|
DecodeMultipleOfflineStreams
|
||||||
GetOfflineStreamResult
|
DecodeOfflineStream
|
||||||
|
DestroyOfflineRecognizer
|
||||||
DestroyOfflineRecognizerResult
|
DestroyOfflineRecognizerResult
|
||||||
|
DestroyOfflineStream
|
||||||
|
DestroyOfflineStreamResultJson
|
||||||
|
GetOfflineStreamResult
|
||||||
|
GetOfflineStreamResultAsJson
|
||||||
|
PrintOfflineRecognizerConfig
|
||||||
# online kws
|
# online kws
|
||||||
CreateKeywordSpotter
|
CreateKeywordSpotter
|
||||||
DestroyKeywordSpotter
|
DestroyKeywordSpotter
|
||||||
|
|||||||
Reference in New Issue
Block a user