Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2024-04-05 20:24:27 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-04-05 20:24:27 +0800
Commit
c1c0f5bafd9911a4eced5e23f3054adc307a8bc7
c1c0f5ba
1 parent
dbff2eaa
return timestamps for WebAssembly (#737)
隐藏空白字符变更
内嵌
并排对比
正在显示
20 个修改的文件
包含
88 行增加
和
34 行删除
CMakeLists.txt
build-aarch64-linux-gnu.sh
build-arm-linux-gnueabihf.sh
build-wasm-simd-nodejs.sh
nodejs-examples/test-offline-nemo-ctc.js
nodejs-examples/test-offline-paraformer.js
nodejs-examples/test-offline-transducer.js
nodejs-examples/test-offline-whisper.js
nodejs-examples/test-online-paraformer-microphone.js
nodejs-examples/test-online-paraformer.js
nodejs-examples/test-online-transducer-microphone.js
nodejs-examples/test-online-transducer.js
nodejs-examples/test-online-zipformer2-ctc-hlg.js
nodejs-examples/test-online-zipformer2-ctc.js
sherpa-onnx/c-api/c-api.cc
sherpa-onnx/c-api/c-api.h
wasm/asr/CMakeLists.txt
wasm/asr/app-asr.js
wasm/asr/sherpa-onnx-asr.js
wasm/nodejs/CMakeLists.txt
CMakeLists.txt
查看文件 @
c1c0f5b
cmake_minimum_required
(
VERSION 3.13 FATAL_ERROR
)
project
(
sherpa-onnx
)
set
(
SHERPA_ONNX_VERSION
"1.9.1
5
"
)
set
(
SHERPA_ONNX_VERSION
"1.9.1
6
"
)
# Disable warning about
#
...
...
build-aarch64-linux-gnu.sh
查看文件 @
c1c0f5b
...
...
@@ -57,7 +57,7 @@ cmake \
-DSHERPA_ONNX_ENABLE_CHECK
=
OFF
\
-DSHERPA_ONNX_ENABLE_PORTAUDIO
=
OFF
\
-DSHERPA_ONNX_ENABLE_JNI
=
OFF
\
-DSHERPA_ONNX_ENABLE_C_API
=
O
FF
\
-DSHERPA_ONNX_ENABLE_C_API
=
O
N
\
-DSHERPA_ONNX_ENABLE_WEBSOCKET
=
OFF
\
-DCMAKE_TOOLCHAIN_FILE
=
../toolchains/aarch64-linux-gnu.toolchain.cmake
\
..
...
...
build-arm-linux-gnueabihf.sh
查看文件 @
c1c0f5b
...
...
@@ -52,7 +52,7 @@ cmake \
-DSHERPA_ONNX_ENABLE_CHECK
=
OFF
\
-DSHERPA_ONNX_ENABLE_PORTAUDIO
=
OFF
\
-DSHERPA_ONNX_ENABLE_JNI
=
OFF
\
-DSHERPA_ONNX_ENABLE_C_API
=
O
FF
\
-DSHERPA_ONNX_ENABLE_C_API
=
O
N
\
-DSHERPA_ONNX_ENABLE_WEBSOCKET
=
OFF
\
-DCMAKE_TOOLCHAIN_FILE
=
../toolchains/arm-linux-gnueabihf.toolchain.cmake
\
..
...
...
build-wasm-simd-nodejs.sh
查看文件 @
c1c0f5b
...
...
@@ -57,7 +57,7 @@ cmake \
-DSHERPA_ONNX_ENABLE_BINARY
=
OFF
\
-DSHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY
=
OFF
\
..
make -j
10
make -j
3
make install
ls -lh install/bin/wasm/nodejs
...
...
nodejs-examples/test-offline-nemo-ctc.js
查看文件 @
c1c0f5b
...
...
@@ -100,7 +100,7 @@ fs.createReadStream(waveFilename, {highWaterMark: 4096})
stream
.
acceptWaveform
(
recognizer
.
config
.
featConfig
.
sampleRate
,
flattened
);
recognizer
.
decode
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
stream
.
free
();
...
...
nodejs-examples/test-offline-paraformer.js
查看文件 @
c1c0f5b
...
...
@@ -100,7 +100,7 @@ fs.createReadStream(waveFilename, {'highWaterMark': 4096})
stream
.
acceptWaveform
(
recognizer
.
config
.
featConfig
.
sampleRate
,
flattened
);
recognizer
.
decode
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
stream
.
free
();
...
...
nodejs-examples/test-offline-transducer.js
查看文件 @
c1c0f5b
...
...
@@ -101,7 +101,7 @@ fs.createReadStream(waveFilename, {'highWaterMark': 4096})
stream
.
acceptWaveform
(
recognizer
.
config
.
featConfig
.
sampleRate
,
flattened
);
recognizer
.
decode
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
stream
.
free
();
...
...
nodejs-examples/test-offline-whisper.js
查看文件 @
c1c0f5b
...
...
@@ -100,7 +100,7 @@ fs.createReadStream(waveFilename, {'highWaterMark': 4096})
stream
.
acceptWaveform
(
recognizer
.
config
.
featConfig
.
sampleRate
,
flattened
);
recognizer
.
decode
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
stream
.
free
();
...
...
nodejs-examples/test-online-paraformer-microphone.js
查看文件 @
c1c0f5b
...
...
@@ -86,7 +86,7 @@ ai.on('data', data => {
}
const
isEndpoint
=
recognizer
.
isEndpoint
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
if
(
text
.
length
>
0
&&
lastText
!=
text
)
{
lastText
=
text
;
...
...
nodejs-examples/test-online-paraformer.js
查看文件 @
c1c0f5b
...
...
@@ -75,7 +75,7 @@ function decode(samples) {
while
(
recognizer
.
isReady
(
stream
))
{
recognizer
.
decode
(
stream
);
}
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
}
...
...
nodejs-examples/test-online-transducer-microphone.js
查看文件 @
c1c0f5b
...
...
@@ -88,7 +88,7 @@ ai.on('data', data => {
}
const
isEndpoint
=
recognizer
.
isEndpoint
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
if
(
text
.
length
>
0
&&
lastText
!=
text
)
{
lastText
=
text
;
...
...
nodejs-examples/test-online-transducer.js
查看文件 @
c1c0f5b
...
...
@@ -77,7 +77,7 @@ function decode(samples) {
while
(
recognizer
.
isReady
(
stream
))
{
recognizer
.
decode
(
stream
);
}
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
}
...
...
nodejs-examples/test-online-zipformer2-ctc-hlg.js
查看文件 @
c1c0f5b
...
...
@@ -74,7 +74,7 @@ function decode(samples) {
while
(
recognizer
.
isReady
(
stream
))
{
recognizer
.
decode
(
stream
);
}
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
}
...
...
nodejs-examples/test-online-zipformer2-ctc.js
查看文件 @
c1c0f5b
...
...
@@ -75,7 +75,7 @@ function decode(samples) {
while
(
recognizer
.
isReady
(
stream
))
{
recognizer
.
decode
(
stream
);
}
const
text
=
recognizer
.
getResult
(
stream
);
const
text
=
recognizer
.
getResult
(
stream
)
.
text
;
console
.
log
(
text
);
}
...
...
sherpa-onnx/c-api/c-api.cc
查看文件 @
c1c0f5b
...
...
@@ -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
// ============================================================
...
...
sherpa-onnx/c-api/c-api.h
查看文件 @
c1c0f5b
...
...
@@ -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
// ============================================================
...
...
wasm/asr/CMakeLists.txt
查看文件 @
c1c0f5b
...
...
@@ -13,10 +13,14 @@ set(exported_functions
CreateOnlineRecognizer
CreateOnlineStream
DecodeOnlineStream
DestroyOfflineStreamResultJson
DestroyOnlineRecognizer
DestroyOnlineRecognizerResult
DestroyOnlineStream
DestroyOnlineStreamResultJson
GetOfflineStreamResultAsJson
GetOnlineStreamResult
GetOnlineStreamResultAsJson
InputFinished
IsEndpoint
IsOnlineStreamReady
...
...
wasm/asr/app-asr.js
查看文件 @
c1c0f5b
...
...
@@ -108,7 +108,7 @@ if (navigator.mediaDevices.getUserMedia) {
}
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
)
{
...
...
wasm/asr/sherpa-onnx-asr.js
查看文件 @
c1c0f5b
...
...
@@ -661,13 +661,12 @@ class OfflineRecognizer {
}
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*'
);
const
text
=
this
.
Module
.
UTF8ToString
(
textPtr
);
this
.
Module
.
_DestroyOfflineRecognizerResult
(
r
);
return
text
;
return
ans
;
}
};
...
...
@@ -750,11 +749,13 @@ class OnlineRecognizer {
}
getResult
(
stream
)
{
const
r
=
this
.
Module
.
_GetOnlineStreamResult
(
this
.
handle
,
stream
.
handle
);
const
textPtr
=
this
.
Module
.
getValue
(
r
,
'i8*'
);
const
text
=
this
.
Module
.
UTF8ToString
(
textPtr
);
this
.
Module
.
_DestroyOnlineRecognizerResult
(
r
);
return
text
;
const
r
=
this
.
Module
.
_GetOnlineStreamResultAsJson
(
this
.
handle
,
stream
.
handle
);
const
jsonStr
=
this
.
Module
.
UTF8ToString
(
r
);
const
ans
=
JSON
.
parse
(
jsonStr
);
this
.
Module
.
_DestroyOnlineStreamResultJson
(
r
);
return
ans
;
}
}
...
...
wasm/nodejs/CMakeLists.txt
查看文件 @
c1c0f5b
...
...
@@ -21,22 +21,26 @@ set(exported_functions
DestroyOnlineRecognizer
DestroyOnlineRecognizerResult
DestroyOnlineStream
DestroyOnlineStreamResultJson
GetOnlineStreamResult
GetOnlineStreamResultAsJson
InputFinished
IsEndpoint
IsOnlineStreamReady
Reset
# non-streaming ASR
PrintOfflineRecognizerConfig
AcceptWaveformOffline
CreateOfflineRecognizer
DestroyOfflineRecognizer
CreateOfflineStream
DestroyOfflineStream
AcceptWaveformOffline
DecodeOfflineStream
DecodeMultipleOfflineStreams
GetOfflineStreamResult
DecodeOfflineStream
DestroyOfflineRecognizer
DestroyOfflineRecognizerResult
DestroyOfflineStream
DestroyOfflineStreamResultJson
GetOfflineStreamResult
GetOfflineStreamResultAsJson
PrintOfflineRecognizerConfig
# online kws
CreateKeywordSpotter
DestroyKeywordSpotter
...
...
请
注册
或
登录
后发表评论