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-09-22 13:28:19 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2023-09-22 13:28:19 +0800
Commit
43b2b7760de8e3d103a0081877759c84a0e1472e
43b2b776
1 parent
969fff56
Fix tokens processing for byte-level BPE (#333)
显示空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
40 行增加
和
15 行删除
CMakeLists.txt
sherpa-onnx/csrc/offline-stream.cc
sherpa-onnx/csrc/symbol-table.cc
CMakeLists.txt
查看文件 @
43b2b77
cmake_minimum_required
(
VERSION 3.13 FATAL_ERROR
)
project
(
sherpa-onnx
)
set
(
SHERPA_ONNX_VERSION
"1.7.1
7
"
)
set
(
SHERPA_ONNX_VERSION
"1.7.1
8
"
)
# Disable warning about
#
...
...
sherpa-onnx/csrc/offline-stream.cc
查看文件 @
43b2b77
...
...
@@ -8,9 +8,9 @@
#include <algorithm>
#include <cmath>
#include <iomanip>
#include "kaldi-native-fbank/csrc/online-feature.h"
#include "nlohmann/json.hpp"
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/offline-recognizer.h"
#include "sherpa-onnx/csrc/resample.h"
...
...
@@ -256,25 +256,50 @@ const OfflineRecognitionResult &OfflineStream::GetResult() const {
return
impl_
->
GetResult
();
}
std
::
string
OfflineRecognitionResult
::
AsJsonString
()
const
{
nlohmann
::
json
j
;
j
[
"text"
]
=
text
;
j
[
"tokens"
]
=
tokens
;
#if 1
// This branch chooses number of decimal points to keep in
// the return json string
std
::
ostringstream
os
;
os
<<
"["
;
os
<<
"{"
;
os
<<
"
\"
text
\"
"
<<
": "
;
os
<<
"
\"
"
<<
text
<<
"
\"
"
<<
", "
;
os
<<
"
\"
"
<<
"timestamps"
<<
"
\"
"
<<
": "
;
os
<<
"
\"
["
;
std
::
string
sep
=
""
;
for
(
auto
t
:
timestamps
)
{
os
<<
sep
<<
std
::
fixed
<<
std
::
setprecision
(
2
)
<<
t
;
sep
=
", "
;
}
os
<<
"]
\"
, "
;
os
<<
"
\"
"
<<
"tokens"
<<
"
\"
"
<<
":"
;
os
<<
"["
;
sep
=
""
;
auto
oldFlags
=
os
.
flags
();
for
(
const
auto
&
t
:
tokens
)
{
if
(
t
.
size
()
==
1
&&
static_cast
<
uint8_t
>
(
t
[
0
])
>
0x7f
)
{
const
uint8_t
*
p
=
reinterpret_cast
<
const
uint8_t
*>
(
t
.
c_str
());
os
<<
sep
<<
"
\"
"
<<
"<0x"
<<
std
::
hex
<<
std
::
uppercase
<<
static_cast
<
uint32_t
>
(
p
[
0
])
<<
">"
<<
"
\"
"
;
os
.
flags
(
oldFlags
);
}
else
{
os
<<
sep
<<
"
\"
"
<<
t
<<
"
\"
"
;
}
sep
=
", "
;
}
os
<<
"]"
;
j
[
"timestamps"
]
=
os
.
str
();
#else
j
[
"timestamps"
]
=
timestamps
;
#endif
os
<<
"}"
;
return
j
.
dump
();
return
os
.
str
();
}
}
// namespace sherpa_onnx
...
...
sherpa-onnx/csrc/symbol-table.cc
查看文件 @
43b2b77
...
...
@@ -51,7 +51,7 @@ void SymbolTable::Init(std::istream &is) {
if
(
id
>=
3
&&
id
<=
258
&&
sym
.
size
()
==
6
&&
sym
[
0
]
==
'<'
&&
sym
[
1
]
==
'0'
&&
sym
[
2
]
==
'x'
&&
sym
[
5
]
==
'>'
)
{
std
::
ostringstream
os
;
os
<<
std
::
hex
<<
(
id
-
3
);
os
<<
std
::
hex
<<
std
::
uppercase
<<
(
id
-
3
);
if
(
std
::
string
(
sym
.
data
()
+
3
,
sym
.
data
()
+
5
)
==
os
.
str
())
{
uint8_t
i
=
id
-
3
;
...
...
请
注册
或
登录
后发表评论