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-09-20 19:04:21 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-09-20 19:04:21 +0800
Commit
d8809b520ee3824b8dea139270c14d98f50ad0b9
d8809b52
1 parent
06b61cca
Fix CI errors introduced by supporting loading keywords from buffers (#1366)
隐藏空白字符变更
内嵌
并排对比
正在显示
8 个修改的文件
包含
55 行增加
和
7 行删除
flutter/sherpa_onnx/lib/src/keyword_spotter.dart
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
scripts/dotnet/KeywordSpotterConfig.cs
scripts/go/_internal/build_linux_arm64.go
scripts/node-addon-api/src/keyword-spotting.cc
swift-api-examples/SherpaOnnx.swift
wasm/kws/sherpa-onnx-kws.js
wasm/kws/sherpa-onnx-wasm-main-kws.cc
flutter/sherpa_onnx/lib/src/keyword_spotter.dart
查看文件 @
d8809b5
...
...
@@ -19,11 +19,13 @@ class KeywordSpotterConfig {
this
.
keywordsScore
=
1.0
,
this
.
keywordsThreshold
=
0.25
,
this
.
keywordsFile
=
''
,
this
.
keywordsBuf
=
''
,
this
.
keywordsBufSize
=
0
,
});
@override
String
toString
()
{
return
'KeywordSpotterConfig(feat:
$feat
, model:
$model
, maxActivePaths:
$maxActivePaths
, numTrailingBlanks:
$numTrailingBlanks
, keywordsScore:
$keywordsScore
, keywordsThreshold:
$keywordsThreshold
, keywordsFile:
$keywordsFile
)'
;
return
'KeywordSpotterConfig(feat:
$feat
, model:
$model
, maxActivePaths:
$maxActivePaths
, numTrailingBlanks:
$numTrailingBlanks
, keywordsScore:
$keywordsScore
, keywordsThreshold:
$keywordsThreshold
, keywordsFile:
$keywordsFile
, keywordsBuf:
$keywordsBuf
, keywordsBufSize:
$keywordsBufSize
)'
;
}
final
FeatureConfig
feat
;
...
...
@@ -35,6 +37,8 @@ class KeywordSpotterConfig {
final
double
keywordsScore
;
final
double
keywordsThreshold
;
final
String
keywordsFile
;
final
String
keywordsBuf
;
final
int
keywordsBufSize
;
}
class
KeywordResult
{
...
...
@@ -89,9 +93,12 @@ class KeywordSpotter {
c
.
ref
.
keywordsScore
=
config
.
keywordsScore
;
c
.
ref
.
keywordsThreshold
=
config
.
keywordsThreshold
;
c
.
ref
.
keywordsFile
=
config
.
keywordsFile
.
toNativeUtf8
();
c
.
ref
.
keywordsBuf
=
config
.
keywordsBuf
.
toNativeUtf8
();
c
.
ref
.
keywordsBufSize
=
config
.
keywordsBufSize
;
final
ptr
=
SherpaOnnxBindings
.
createKeywordSpotter
?.
call
(
c
)
??
nullptr
;
calloc
.
free
(
c
.
ref
.
keywordsBuf
);
calloc
.
free
(
c
.
ref
.
keywordsFile
);
calloc
.
free
(
c
.
ref
.
model
.
bpeVocab
);
calloc
.
free
(
c
.
ref
.
model
.
modelingUnit
);
...
...
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
查看文件 @
d8809b5
...
...
@@ -371,6 +371,11 @@ final class SherpaOnnxKeywordSpotterConfig extends Struct {
external
double
keywordsThreshold
;
external
Pointer
<
Utf8
>
keywordsFile
;
external
Pointer
<
Utf8
>
keywordsBuf
;
@Int32
()
external
int
keywordsBufSize
;
}
final
class
SherpaOnnxOfflinePunctuation
extends
Opaque
{}
...
...
scripts/dotnet/KeywordSpotterConfig.cs
查看文件 @
d8809b5
...
...
@@ -17,6 +17,8 @@ namespace SherpaOnnx
KeywordsScore
=
1.0F
;
KeywordsThreshold
=
0.25F
;
KeywordsFile
=
""
;
KeywordsBuf
=
""
;
KeywordsBufSize
=
0
;
}
public
FeatureConfig
FeatConfig
;
public
OnlineModelConfig
ModelConfig
;
...
...
@@ -28,5 +30,10 @@ namespace SherpaOnnx
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
KeywordsFile
;
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
public
string
KeywordsBuf
;
public
int
KeywordsBufSize
;
}
}
...
...
scripts/go/_internal/build_linux_arm64.go
查看文件 @
d8809b5
...
...
@@ -2,5 +2,5 @@
package
sherpa_onnx
// #cgo LDFLAGS: -L ${SRCDIR}/lib/aarch64-unknown-linux-gnu -lsherpa-onnx-c-api -l
sherpa-onnx-core -lkaldi-native-fbank-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_cor
e -Wl,-rpath,${SRCDIR}/lib/aarch64-unknown-linux-gnu
// #cgo LDFLAGS: -L ${SRCDIR}/lib/aarch64-unknown-linux-gnu -lsherpa-onnx-c-api -l
onnxruntim
e -Wl,-rpath,${SRCDIR}/lib/aarch64-unknown-linux-gnu
import
"C"
...
...
scripts/node-addon-api/src/keyword-spotting.cc
查看文件 @
d8809b5
...
...
@@ -43,6 +43,8 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
SHERPA_ONNX_ASSIGN_ATTR_FLOAT
(
keywords_score
,
keywordsScore
);
SHERPA_ONNX_ASSIGN_ATTR_FLOAT
(
keywords_threshold
,
keywordsThreshold
);
SHERPA_ONNX_ASSIGN_ATTR_STR
(
keywords_file
,
keywordsFile
);
SHERPA_ONNX_ASSIGN_ATTR_STR
(
keywords_buf
,
keywordsBuf
);
SHERPA_ONNX_ASSIGN_ATTR_INT32
(
keywords_buf_size
,
keywordsBufSize
);
SherpaOnnxKeywordSpotter
*
kws
=
SherpaOnnxCreateKeywordSpotter
(
&
c
);
...
...
@@ -86,6 +88,10 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
delete
[]
c
.
keywords_file
;
}
if
(
c
.
keywords_buf
)
{
delete
[]
c
.
keywords_buf
;
}
if
(
!
kws
)
{
Napi
::
TypeError
::
New
(
env
,
"Please check your config!"
)
.
ThrowAsJavaScriptException
();
...
...
swift-api-examples/SherpaOnnx.swift
查看文件 @
d8809b5
...
...
@@ -966,7 +966,9 @@ func sherpaOnnxKeywordSpotterConfig(
maxActivePaths
:
Int
=
4
,
numTrailingBlanks
:
Int
=
1
,
keywordsScore
:
Float
=
1.0
,
keywordsThreshold
:
Float
=
0.25
keywordsThreshold
:
Float
=
0.25
,
keywordsBuf
:
String
=
""
,
keywordsBufSize
:
Int
=
0
)
->
SherpaOnnxKeywordSpotterConfig
{
return
SherpaOnnxKeywordSpotterConfig
(
feat_config
:
featConfig
,
...
...
@@ -975,7 +977,9 @@ func sherpaOnnxKeywordSpotterConfig(
num_trailing_blanks
:
Int32
(
numTrailingBlanks
),
keywords_score
:
keywordsScore
,
keywords_threshold
:
keywordsThreshold
,
keywords_file
:
toCPointer
(
keywordsFile
)
keywords_file
:
toCPointer
(
keywordsFile
),
keywords_buf
:
toCPointer
(
keywordsBuf
),
keywords_buf_size
:
Int32
(
keywordsBufSize
)
)
}
...
...
wasm/kws/sherpa-onnx-kws.js
查看文件 @
d8809b5
...
...
@@ -172,10 +172,18 @@ function initKwsConfig(config, Module) {
};
}
if
(
!
(
'keywordsBuf'
in
config
))
{
config
.
keywordsBuf
=
''
;
}
if
(
!
(
'keywordsBufSize'
in
config
))
{
config
.
keywordsBufSize
=
0
;
}
let
featConfig
=
initFeatureExtractorConfig
(
config
.
featConfig
,
Module
);
let
modelConfig
=
initModelConfig
(
config
.
modelConfig
,
Module
);
let
numBytes
=
featConfig
.
len
+
modelConfig
.
len
+
4
*
5
;
let
numBytes
=
featConfig
.
len
+
modelConfig
.
len
+
4
*
7
;
let
ptr
=
Module
.
_malloc
(
numBytes
);
let
offset
=
0
;
...
...
@@ -198,11 +206,22 @@ function initKwsConfig(config, Module) {
offset
+=
4
;
let
keywordsLen
=
Module
.
lengthBytesUTF8
(
config
.
keywords
)
+
1
;
let
keywordsBuffer
=
Module
.
_malloc
(
keywordsLen
);
let
keywordsBufLen
=
Module
.
lengthBytesUTF8
(
config
.
keywordsBuf
)
+
1
;
let
keywordsBuffer
=
Module
.
_malloc
(
keywordsLen
+
keywordsBufLen
);
Module
.
stringToUTF8
(
config
.
keywords
,
keywordsBuffer
,
keywordsLen
);
Module
.
stringToUTF8
(
config
.
keywordsBuf
,
keywordsBuffer
+
keywordsLen
,
keywordsBufLen
);
Module
.
setValue
(
ptr
+
offset
,
keywordsBuffer
,
'i8*'
);
offset
+=
4
;
Module
.
setValue
(
ptr
+
offset
,
keywordsBuffer
+
keywordsLen
,
'i8*'
);
offset
+=
4
;
Module
.
setValue
(
ptr
+
offset
,
config
.
keywordsBufLen
,
'i32'
);
offset
+=
4
;
return
{
ptr
:
ptr
,
len
:
numBytes
,
featConfig
:
featConfig
,
modelConfig
:
modelConfig
,
keywordsBuffer
:
keywordsBuffer
...
...
wasm/kws/sherpa-onnx-wasm-main-kws.cc
查看文件 @
d8809b5
...
...
@@ -24,7 +24,7 @@ static_assert(sizeof(SherpaOnnxOnlineModelConfig) ==
static_assert
(
sizeof
(
SherpaOnnxFeatureConfig
)
==
2
*
4
,
""
);
static_assert
(
sizeof
(
SherpaOnnxKeywordSpotterConfig
)
==
sizeof
(
SherpaOnnxFeatureConfig
)
+
sizeof
(
SherpaOnnxOnlineModelConfig
)
+
5
*
4
,
sizeof
(
SherpaOnnxOnlineModelConfig
)
+
7
*
4
,
""
);
void
CopyHeap
(
const
char
*
src
,
int32_t
num_bytes
,
char
*
dst
)
{
...
...
请
注册
或
登录
后发表评论