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-06-14 10:22:56 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-06-14 10:22:56 +0800
Commit
c214d8fb741b76d84d450f2bddcfed4f9ad4b4ff
c214d8fb
1 parent
155f22d5
fix kws for WebAssembly (#999)
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
30 行增加
和
6 行删除
wasm/kws/app.js
wasm/kws/sherpa-onnx-kws.js
wasm/kws/sherpa-onnx-wasm-main-kws.cc
wasm/kws/app.js
查看文件 @
c214d8f
...
...
@@ -106,9 +106,9 @@ if (navigator.mediaDevices.getUserMedia) {
let
result
=
recognizer
.
getResult
(
recognizer_stream
);
console
.
log
(
result
)
if
(
result
.
keyword
.
length
>
0
)
{
console
.
log
(
result
)
lastResult
=
result
;
resultList
.
push
(
JSON
.
stringify
(
result
));
}
...
...
@@ -287,4 +287,4 @@ function downsampleBuffer(buffer, exportSampleRate) {
offsetBuffer
=
nextOffsetBuffer
;
}
return
result
;
};
\ No newline at end of file
};
...
...
wasm/kws/sherpa-onnx-kws.js
查看文件 @
c214d8f
...
...
@@ -67,7 +67,7 @@ function initModelConfig(config, Module) {
const
paraformer_len
=
2
*
4
const
ctc_len
=
1
*
4
const
len
=
transducer
.
len
+
paraformer_len
+
ctc_len
+
5
*
4
;
const
len
=
transducer
.
len
+
paraformer_len
+
ctc_len
+
7
*
4
;
const
ptr
=
Module
.
_malloc
(
len
);
let
offset
=
0
;
...
...
@@ -76,7 +76,10 @@ function initModelConfig(config, Module) {
const
tokensLen
=
Module
.
lengthBytesUTF8
(
config
.
tokens
)
+
1
;
const
providerLen
=
Module
.
lengthBytesUTF8
(
config
.
provider
)
+
1
;
const
modelTypeLen
=
Module
.
lengthBytesUTF8
(
config
.
modelType
)
+
1
;
const
bufferLen
=
tokensLen
+
providerLen
+
modelTypeLen
;
const
modelingUnitLen
=
Module
.
lengthBytesUTF8
(
config
.
modelingUnit
||
''
)
+
1
;
const
bpeVocabLen
=
Module
.
lengthBytesUTF8
(
config
.
bpeVocab
||
''
)
+
1
;
const
bufferLen
=
tokensLen
+
providerLen
+
modelTypeLen
+
modelingUnitLen
+
bpeVocabLen
;
const
buffer
=
Module
.
_malloc
(
bufferLen
);
offset
=
0
;
...
...
@@ -87,6 +90,14 @@ function initModelConfig(config, Module) {
offset
+=
providerLen
;
Module
.
stringToUTF8
(
config
.
modelType
,
buffer
+
offset
,
modelTypeLen
);
offset
+=
modelTypeLen
;
Module
.
stringToUTF8
(
config
.
modelingUnit
||
''
,
buffer
+
offset
,
modelingUnitLen
);
offset
+=
modelingUnitLen
;
Module
.
stringToUTF8
(
config
.
bpeVocab
||
''
,
buffer
+
offset
,
bpeVocabLen
);
offset
+=
bpeVocabLen
;
offset
=
transducer
.
len
+
paraformer_len
+
ctc_len
;
Module
.
setValue
(
ptr
+
offset
,
buffer
,
'i8*'
);
// tokens
...
...
@@ -105,6 +116,17 @@ function initModelConfig(config, Module) {
ptr
+
offset
,
buffer
+
tokensLen
+
providerLen
,
'i8*'
);
// modelType
offset
+=
4
;
Module
.
setValue
(
ptr
+
offset
,
buffer
+
tokensLen
+
providerLen
+
modelTypeLen
,
'i8*'
);
// modelingUnit
offset
+=
4
;
Module
.
setValue
(
ptr
+
offset
,
buffer
+
tokensLen
+
providerLen
+
modelTypeLen
+
modelingUnitLen
,
'i8*'
);
// bpeVocab
offset
+=
4
;
return
{
buffer
:
buffer
,
ptr
:
ptr
,
len
:
len
,
transducer
:
transducer
}
...
...
@@ -248,7 +270,9 @@ function createKws(Module, myConfig) {
provider
:
'cpu'
,
modelType
:
''
,
numThreads
:
1
,
debug
:
1
debug
:
1
,
modelingUnit
:
'cjkchar'
,
bpeVocab
:
''
,
};
let
featConfig
=
{
...
...
wasm/kws/sherpa-onnx-wasm-main-kws.cc
查看文件 @
c214d8f
...
...
@@ -19,7 +19,7 @@ static_assert(sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) == 1 * 4, "");
static_assert
(
sizeof
(
SherpaOnnxOnlineModelConfig
)
==
sizeof
(
SherpaOnnxOnlineTransducerModelConfig
)
+
sizeof
(
SherpaOnnxOnlineParaformerModelConfig
)
+
sizeof
(
SherpaOnnxOnlineZipformer2CtcModelConfig
)
+
5
*
4
,
sizeof
(
SherpaOnnxOnlineZipformer2CtcModelConfig
)
+
7
*
4
,
""
);
static_assert
(
sizeof
(
SherpaOnnxFeatureConfig
)
==
2
*
4
,
""
);
static_assert
(
sizeof
(
SherpaOnnxKeywordSpotterConfig
)
==
...
...
请
注册
或
登录
后发表评论