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-08-14 20:53:36 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2023-08-14 20:53:36 +0800
Commit
313debe45c6926057b68f1ff5b61ba47bc2f2e9f
313debe4
1 parent
bc791d49
small fixes to python api examples (#269)
显示空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
25 行增加
和
16 行删除
python-api-examples/speech-recognition-from-microphone-with-endpoint-detection.py
python-api-examples/speech-recognition-from-microphone.py
python-api-examples/speech-recognition-from-microphone-with-endpoint-detection.py
查看文件 @
313debe
...
...
@@ -82,8 +82,7 @@ def get_args():
return
parser
.
parse_args
()
def
create_recognizer
():
args
=
get_args
()
def
create_recognizer
(
args
):
assert_file_exists
(
args
.
encoder
)
assert_file_exists
(
args
.
decoder
)
assert_file_exists
(
args
.
joiner
)
...
...
@@ -110,7 +109,18 @@ def create_recognizer():
def
main
():
recognizer
=
create_recognizer
()
args
=
get_args
()
devices
=
sd
.
query_devices
()
if
len
(
devices
)
==
0
:
print
(
"No microphone devices found"
)
sys
.
exit
(
0
)
print
(
devices
)
default_input_device_idx
=
sd
.
default
.
device
[
0
]
print
(
f
'Use default device: {devices[default_input_device_idx]["name"]}'
)
recognizer
=
create_recognizer
(
args
)
print
(
"Started! Please speak"
)
# The model is using 16 kHz, we use 48 kHz here to demonstrate that
...
...
@@ -145,10 +155,6 @@ def main():
if
__name__
==
"__main__"
:
devices
=
sd
.
query_devices
()
print
(
devices
)
default_input_device_idx
=
sd
.
default
.
device
[
0
]
print
(
f
'Use default device: {devices[default_input_device_idx]["name"]}'
)
try
:
main
()
...
...
python-api-examples/speech-recognition-from-microphone.py
查看文件 @
313debe
...
...
@@ -10,7 +10,7 @@ import argparse
import
sys
from
pathlib
import
Path
from
typing
import
List
,
Tuple
from
typing
import
List
import
sentencepiece
as
spm
try
:
...
...
@@ -136,8 +136,7 @@ def get_args():
return
parser
.
parse_args
()
def
create_recognizer
():
args
=
get_args
()
def
create_recognizer
(
args
):
assert_file_exists
(
args
.
encoder
)
assert_file_exists
(
args
.
decoder
)
assert_file_exists
(
args
.
joiner
)
...
...
@@ -185,13 +184,22 @@ def encode_contexts(args, contexts: List[str]) -> List[List[int]]:
def
main
():
args
=
get_args
()
devices
=
sd
.
query_devices
()
if
len
(
devices
)
==
0
:
print
(
"No microphone devices found"
)
sys
.
exit
(
0
)
print
(
devices
)
default_input_device_idx
=
sd
.
default
.
device
[
0
]
print
(
f
'Use default device: {devices[default_input_device_idx]["name"]}'
)
contexts_list
=
[]
contexts
=
[
x
.
strip
()
.
upper
()
for
x
in
args
.
contexts
.
split
(
"/"
)
if
x
.
strip
()]
if
contexts
:
print
(
f
"Contexts list: {contexts}"
)
contexts_list
=
encode_contexts
(
args
,
contexts
)
recognizer
=
create_recognizer
()
recognizer
=
create_recognizer
(
args
)
print
(
"Started! Please speak"
)
# The model is using 16 kHz, we use 48 kHz here to demonstrate that
...
...
@@ -217,11 +225,6 @@ def main():
if
__name__
==
"__main__"
:
devices
=
sd
.
query_devices
()
print
(
devices
)
default_input_device_idx
=
sd
.
default
.
device
[
0
]
print
(
f
'Use default device: {devices[default_input_device_idx]["name"]}'
)
try
:
main
()
except
KeyboardInterrupt
:
...
...
请
注册
或
登录
后发表评论