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
Daniel Doña
2024-04-26 03:19:32 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-04-26 09:19:32 +0800
Commit
fa2429920f52166334e117644e340a533e512f6b
fa242992
1 parent
f7b37356
Add function 'tolowerUnicode' in sherpa-onnx-microphone (fix #791) (#812)
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
28 行增加
和
6 行删除
sherpa-onnx/csrc/sherpa-onnx-microphone.cc
sherpa-onnx/csrc/sherpa-onnx-microphone.cc
查看文件 @
fa24299
...
...
@@ -7,7 +7,8 @@
#include <stdlib.h>
#include <algorithm>
#include <cctype> // std::tolower
#include <clocale>
#include <cwctype>
#include "portaudio.h" // NOLINT
#include "sherpa-onnx/csrc/display.h"
...
...
@@ -37,6 +38,31 @@ static void Handler(int32_t sig) {
fprintf
(
stderr
,
"
\n
Caught Ctrl + C. Exiting...
\n
"
);
}
static
std
::
string
tolowerUnicode
(
const
std
::
string
&
input_str
)
{
// Use system locale
std
::
setlocale
(
LC_ALL
,
""
);
// From char string to wchar string
std
::
wstring
input_wstr
(
input_str
.
size
()
+
1
,
'\0'
);
std
::
mbstowcs
(
&
input_wstr
[
0
],
input_str
.
c_str
(),
input_str
.
size
());
std
::
wstring
lowercase_wstr
;
for
(
wchar_t
wc
:
input_wstr
)
{
if
(
std
::
iswupper
(
wc
))
{
lowercase_wstr
+=
std
::
towlower
(
wc
);
}
else
{
lowercase_wstr
+=
wc
;
}
}
// Back to char string
std
::
string
lowercase_str
(
input_str
.
size
()
+
1
,
'\0'
);
std
:
wcstombs
(
&
lowercase_str
[
0
],
lowercase_wstr
.
c_str
(),
lowercase_wstr
.
size
());
return
lowercase_str
;
}
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
signal
(
SIGINT
,
Handler
);
...
...
@@ -172,11 +198,7 @@ for a list of pre-trained models to download.
if
(
!
text
.
empty
()
&&
last_text
!=
text
)
{
last_text
=
text
;
std
::
transform
(
text
.
begin
(),
text
.
end
(),
text
.
begin
(),
[](
auto
c
)
{
return
std
::
tolower
(
c
);
});
display
.
Print
(
segment_index
,
text
);
display
.
Print
(
segment_index
,
tolowerUnicode
(
text
));
fflush
(
stderr
);
}
...
...
请
注册
或
登录
后发表评论