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
2023-10-11 12:20:50 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2023-10-11 12:20:50 +0800
Commit
98b67ad8501b6a98304104d81345aed96cb5576a
98b67ad8
1 parent
84550570
Fix reading hotwords file for android (#354)
显示空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
46 行增加
和
4 行删除
sherpa-onnx/csrc/online-recognizer-transducer-impl.h
sherpa-onnx/csrc/online-recognizer-transducer-impl.h
查看文件 @
98b67ad
...
...
@@ -12,6 +12,13 @@
#include <utility>
#include <vector>
#if __ANDROID_API__ >= 9
#include <strstream>
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/online-lm.h"
...
...
@@ -62,14 +69,15 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
model_
(
OnlineTransducerModel
::
Create
(
config
.
model_config
)),
sym_
(
config
.
model_config
.
tokens
),
endpoint_
(
config_
.
endpoint_config
)
{
if
(
!
config_
.
hotwords_file
.
empty
())
{
InitHotwords
();
}
if
(
sym_
.
contains
(
"<unk>"
))
{
unk_id_
=
sym_
[
"<unk>"
];
}
if
(
config
.
decoding_method
==
"modified_beam_search"
)
{
if
(
!
config_
.
hotwords_file
.
empty
())
{
InitHotwords
();
}
if
(
!
config_
.
lm_config
.
model
.
empty
())
{
lm_
=
OnlineLM
::
Create
(
config
.
lm_config
);
}
...
...
@@ -99,6 +107,17 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
}
if
(
config
.
decoding_method
==
"modified_beam_search"
)
{
#if 0
// TODO(fangjun): Implement it
if (!config_.lm_config.model.empty()) {
lm_ = OnlineLM::Create(mgr, config.lm_config);
}
#endif
if
(
!
config_
.
hotwords_file
.
empty
())
{
InitHotwords
(
mgr
);
}
decoder_
=
std
::
make_unique
<
OnlineTransducerModifiedBeamSearchDecoder
>
(
model_
.
get
(),
lm_
.
get
(),
config_
.
max_active_paths
,
config_
.
lm_config
.
scale
,
unk_id_
);
...
...
@@ -268,6 +287,7 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
s
->
Reset
();
}
private
:
void
InitHotwords
()
{
// each line in hotwords_file contains space-separated words
...
...
@@ -286,7 +306,29 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
std
::
make_shared
<
ContextGraph
>
(
hotwords_
,
config_
.
hotwords_score
);
}
private
:
#if __ANDROID_API__ >= 9
void
InitHotwords
(
AAssetManager
*
mgr
)
{
// each line in hotwords_file contains space-separated words
auto
buf
=
ReadFile
(
mgr
,
config_
.
hotwords_file
);
std
::
istrstream
is
(
buf
.
data
(),
buf
.
size
());
if
(
!
is
)
{
SHERPA_ONNX_LOGE
(
"Open hotwords file failed: %s"
,
config_
.
hotwords_file
.
c_str
());
exit
(
-
1
);
}
if
(
!
EncodeHotwords
(
is
,
sym_
,
&
hotwords_
))
{
SHERPA_ONNX_LOGE
(
"Encode hotwords failed."
);
exit
(
-
1
);
}
hotwords_graph_
=
std
::
make_shared
<
ContextGraph
>
(
hotwords_
,
config_
.
hotwords_score
);
}
#endif
void
InitOnlineStream
(
OnlineStream
*
stream
)
const
{
auto
r
=
decoder_
->
GetEmptyResult
();
...
...
请
注册
或
登录
后发表评论