Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
4b76a01c
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
207
Star
8425
Fork
1598
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
245
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DeepSpeech
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
245
Issue
245
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b76a01c
编写于
4月 21, 2022
作者:
X
xiongxinlei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update en readme.md, test=doc
上级
1a0c2bea
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
497 addition
and
150 deletion
+497
-150
demos/streaming_asr_server/README.md
demos/streaming_asr_server/README.md
+258
-149
paddlespeech/server/bin/paddlespeech_client.py
paddlespeech/server/bin/paddlespeech_client.py
+1
-1
paddlespeech/server/tests/asr/online/README.md
paddlespeech/server/tests/asr/online/README.md
+35
-0
paddlespeech/server/tests/asr/online/README_cn.md
paddlespeech/server/tests/asr/online/README_cn.md
+42
-0
paddlespeech/server/tests/asr/online/microphone_client.py
paddlespeech/server/tests/asr/online/microphone_client.py
+161
-0
未找到文件。
demos/streaming_asr_server/README.md
浏览文件 @
4b76a01c
此差异已折叠。
点击以展开。
paddlespeech/server/bin/paddlespeech_client.py
浏览文件 @
4b76a01c
...
...
@@ -35,7 +35,7 @@ from paddlespeech.server.utils.audio_process import wav2pcm
from
paddlespeech.server.utils.util
import
wav2base64
__all__
=
[
'TTSClientExecutor'
,
'ASRClientExecutor'
,
'ASRClientExecutor'
,
'TTSClientExecutor'
,
'ASRClientExecutor'
,
'ASR
Online
ClientExecutor'
,
'CLSClientExecutor'
]
...
...
paddlespeech/server/tests/asr/online/README.md
0 → 100644
浏览文件 @
4b76a01c
(
[
简体中文
](
./README_cn.md
)
|English)
# Speech Service
## Introduction
This document introduces a client for streaming asr service: microphone
## Usage
### 1. Install
Refer
[
Install
](
https://github.com/PaddlePaddle/PaddleSpeech/blob/develop/docs/source/install.md
)
.
**paddlepaddle 2.2.1**
或以上版本。
It is recommended to use
**paddlepaddle 2.2.1**
or above.
You can choose one way from meduim and hard to install paddlespeech.
### 2. Prepare config File
The input of ASR client demo should be a WAV file(
`.wav`
), and the sample rate must be the same as the model.
Here are sample files for thisASR client demo that can be downloaded:
```
bash
wget
-c
https://paddlespeech.bj.bcebos.com/PaddleAudio/zh.wav
```
### 2. Streaming ASR Client Usage
-
microphone
```
python microphone_client.py
```
paddlespeech/server/tests/asr/online/README_cn.md
0 → 100644
浏览文件 @
4b76a01c
(
[
English
](
./README.md
)
|中文)
# 语音服务
## 介绍
本文档介绍如何使用流式ASR的一种不同客户端:麦克风。
## 使用方法
### 1. 安装
请看
[
安装文档
](
https://github.com/PaddlePaddle/PaddleSpeech/blob/develop/docs/source/install.md
)
.
推荐使用
**paddlepaddle 2.2.1**
或以上版本。
你可以从 medium,hard 三中方式中选择一种方式安装 PaddleSpeech。
### 2. 准备测试文件
这个 ASR client 的输入应该是一个 WAV 文件(
`.wav`
),并且采样率必须与模型的采样率相同。
可以下载此 ASR client的示例音频:
```
bash
wget
-c
https://paddlespeech.bj.bcebos.com/PaddleAudio/zh.wav
```
### 2. 流式 ASR 客户端使用方法
-
Python模拟流式服务命令行
```
# 流式ASR
paddlespeech_client asr_online --server_ip 127.0.0.1 --port 8091 --input ./zh.wav
```
-
麦克风
```
# 直接调用麦克风设备
python microphone_client.py
```
paddlespeech/server/tests/asr/online/microphone_client.py
0 → 100644
浏览文件 @
4b76a01c
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
record wave from the mic
"""
import
asyncio
import
json
import
logging
import
threading
import
wave
from
signal
import
SIGINT
from
signal
import
SIGTERM
import
pyaudio
import
websockets
class
ASRAudioHandler
(
threading
.
Thread
):
def
__init__
(
self
,
url
=
"127.0.0.1"
,
port
=
8091
):
threading
.
Thread
.
__init__
(
self
)
self
.
url
=
url
self
.
port
=
port
self
.
url
=
"ws://"
+
self
.
url
+
":"
+
str
(
self
.
port
)
+
"/ws/asr"
self
.
fileName
=
"./output.wav"
self
.
chunk
=
5120
self
.
format
=
pyaudio
.
paInt16
self
.
channels
=
1
self
.
rate
=
16000
self
.
_running
=
True
self
.
_frames
=
[]
self
.
data_backup
=
[]
def
startrecord
(
self
):
"""
start a new thread to record wave
"""
threading
.
_start_new_thread
(
self
.
recording
,
())
def
recording
(
self
):
"""
recording wave
"""
self
.
_running
=
True
self
.
_frames
=
[]
p
=
pyaudio
.
PyAudio
()
stream
=
p
.
open
(
format
=
self
.
format
,
channels
=
self
.
channels
,
rate
=
self
.
rate
,
input
=
True
,
frames_per_buffer
=
self
.
chunk
)
while
(
self
.
_running
):
data
=
stream
.
read
(
self
.
chunk
)
self
.
_frames
.
append
(
data
)
self
.
data_backup
.
append
(
data
)
stream
.
stop_stream
()
stream
.
close
()
p
.
terminate
()
def
save
(
self
):
"""
save wave data
"""
p
=
pyaudio
.
PyAudio
()
wf
=
wave
.
open
(
self
.
fileName
,
'wb'
)
wf
.
setnchannels
(
self
.
channels
)
wf
.
setsampwidth
(
p
.
get_sample_size
(
self
.
format
))
wf
.
setframerate
(
self
.
rate
)
wf
.
writeframes
(
b
''
.
join
(
self
.
data_backup
))
wf
.
close
()
p
.
terminate
()
def
stoprecord
(
self
):
"""
stop recording
"""
self
.
_running
=
False
async
def
run
(
self
):
aa
=
input
(
"是否开始录音? (y/n)"
)
if
aa
.
strip
()
==
"y"
:
self
.
startrecord
()
logging
.
info
(
"*"
*
10
+
"开始录音,请输入语音"
)
async
with
websockets
.
connect
(
self
.
url
)
as
ws
:
# 发送开始指令
audio_info
=
json
.
dumps
(
{
"name"
:
"test.wav"
,
"signal"
:
"start"
,
"nbest"
:
5
},
sort_keys
=
True
,
indent
=
4
,
separators
=
(
','
,
': '
))
await
ws
.
send
(
audio_info
)
msg
=
await
ws
.
recv
()
logging
.
info
(
"receive msg={}"
.
format
(
msg
))
# send bytes data
logging
.
info
(
"结束录音请: Ctrl + c。继续请按回车。"
)
try
:
while
True
:
while
len
(
self
.
_frames
)
>
0
:
await
ws
.
send
(
self
.
_frames
.
pop
(
0
))
msg
=
await
ws
.
recv
()
logging
.
info
(
"receive msg={}"
.
format
(
msg
))
except
asyncio
.
CancelledError
:
# quit
# send finished
audio_info
=
json
.
dumps
(
{
"name"
:
"test.wav"
,
"signal"
:
"end"
,
"nbest"
:
5
},
sort_keys
=
True
,
indent
=
4
,
separators
=
(
','
,
': '
))
await
ws
.
send
(
audio_info
)
msg
=
await
ws
.
recv
()
logging
.
info
(
"receive msg={}"
.
format
(
msg
))
self
.
stoprecord
()
logging
.
info
(
"*"
*
10
+
"录音结束"
)
self
.
save
()
elif
aa
.
strip
()
==
"n"
:
exit
()
else
:
print
(
"无效输入!"
)
exit
()
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
info
(
"asr websocket client start"
)
handler
=
ASRAudioHandler
(
"127.0.0.1"
,
8091
)
loop
=
asyncio
.
get_event_loop
()
main_task
=
asyncio
.
ensure_future
(
handler
.
run
())
for
signal
in
[
SIGINT
,
SIGTERM
]:
loop
.
add_signal_handler
(
signal
,
main_task
.
cancel
)
try
:
loop
.
run_until_complete
(
main_task
)
finally
:
loop
.
close
()
logging
.
info
(
"asr websocket client finished"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录