-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[asr][websocket]add streaming asr demo #1737
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This is the parameter configuration file for PaddleSpeech Serving. | ||
|
||
################################################################################# | ||
# SERVER SETTING # | ||
################################################################################# | ||
host: 0.0.0.0 | ||
port: 8090 | ||
|
||
# The task format in the engin_list is: <speech task>_<engine type> | ||
# task choices = ['asr_online', 'tts_online'] | ||
# protocol = ['websocket', 'http'] (only one can be selected). | ||
# websocket only support online engine type. | ||
protocol: 'websocket' | ||
engine_list: ['asr_online'] | ||
|
||
|
||
################################################################################# | ||
# ENGINE CONFIG # | ||
################################################################################# | ||
|
||
################################### ASR ######################################### | ||
################### speech task: asr; engine_type: online ####################### | ||
asr_online: | ||
model_type: 'deepspeech2online_aishell' | ||
am_model: # the pdmodel file of am static model [optional] | ||
am_params: # the pdiparams file of am static model [optional] | ||
lang: 'zh' | ||
sample_rate: 16000 | ||
cfg_path: | ||
decode_method: | ||
force_yes: True | ||
|
||
am_predictor_conf: | ||
device: # set 'gpu:id' or 'cpu' | ||
switch_ir_optim: True | ||
glog_info: False # True -> print glog | ||
summary: True # False -> do not show predictor config | ||
|
||
chunk_buffer_conf: | ||
frame_duration_ms: 80 | ||
shift_ms: 40 | ||
sample_rate: 16000 | ||
sample_width: 2 | ||
window_n: 7 # frame | ||
shift_n: 4 # frame | ||
window_ms: 20 # ms | ||
shift_ms: 10 # ms |
45 changes: 45 additions & 0 deletions
45
demos/streaming_asr_server/conf/ws_conformer_application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This is the parameter configuration file for PaddleSpeech Serving. | ||
|
||
################################################################################# | ||
# SERVER SETTING # | ||
################################################################################# | ||
host: 0.0.0.0 | ||
port: 8090 | ||
|
||
# The task format in the engin_list is: <speech task>_<engine type> | ||
# task choices = ['asr_online', 'tts_online'] | ||
# protocol = ['websocket', 'http'] (only one can be selected). | ||
# websocket only support online engine type. | ||
protocol: 'websocket' | ||
engine_list: ['asr_online'] | ||
|
||
|
||
################################################################################# | ||
# ENGINE CONFIG # | ||
################################################################################# | ||
|
||
################################### ASR ######################################### | ||
################### speech task: asr; engine_type: online ####################### | ||
asr_online: | ||
model_type: 'conformer_online_multicn' | ||
am_model: # the pdmodel file of am static model [optional] | ||
am_params: # the pdiparams file of am static model [optional] | ||
lang: 'zh' | ||
sample_rate: 16000 | ||
cfg_path: | ||
decode_method: | ||
force_yes: True | ||
device: # cpu or gpu:id | ||
am_predictor_conf: | ||
device: # set 'gpu:id' or 'cpu' | ||
switch_ir_optim: True | ||
glog_info: False # True -> print glog | ||
summary: True # False -> do not show predictor config | ||
|
||
chunk_buffer_conf: | ||
window_n: 7 # frame | ||
shift_n: 4 # frame | ||
window_ms: 25 # ms | ||
shift_ms: 10 # ms | ||
sample_rate: 16000 | ||
sample_width: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# start the streaming asr service | ||
paddlespeech_server start --config_file ./conf/ws_conformer_application.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# download the test wav | ||
wget -c https://paddlespeech.bj.bcebos.com/PaddleAudio/zh.wav | ||
|
||
# read the wav and pass it to service | ||
python3 websocket_client.py --wavfile ./zh.wav |
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# 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. | ||
#!/usr/bin/python | ||
# -*- coding: UTF-8 -*- | ||
import argparse | ||
import asyncio | ||
import codecs | ||
import logging | ||
import os | ||
|
||
from paddlespeech.cli.log import logger | ||
from paddlespeech.server.utils.audio_handler import ASRAudioHandler | ||
|
||
|
||
def main(args): | ||
logger.info("asr websocket client start") | ||
handler = ASRAudioHandler("127.0.0.1", 8090) | ||
loop = asyncio.get_event_loop() | ||
|
||
# support to process single audio file | ||
if args.wavfile and os.path.exists(args.wavfile): | ||
logger.info(f"start to process the wavscp: {args.wavfile}") | ||
result = loop.run_until_complete(handler.run(args.wavfile)) | ||
result = result["asr_results"] | ||
logger.info(f"asr websocket client finished : {result}") | ||
|
||
# support to process batch audios from wav.scp | ||
if args.wavscp and os.path.exists(args.wavscp): | ||
logging.info(f"start to process the wavscp: {args.wavscp}") | ||
with codecs.open(args.wavscp, 'r', encoding='utf-8') as f,\ | ||
codecs.open("result.txt", 'w', encoding='utf-8') as w: | ||
for line in f: | ||
utt_name, utt_path = line.strip().split() | ||
result = loop.run_until_complete(handler.run(utt_path)) | ||
result = result["asr_results"] | ||
w.write(f"{utt_name} {result}\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
logger.info("Start to do streaming asr client") | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--wavfile", | ||
action="store", | ||
help="wav file path ", | ||
default="./16_audio.wav") | ||
parser.add_argument( | ||
"--wavscp", type=str, default=None, help="The batch audios dict text") | ||
args = parser.parse_args() | ||
|
||
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
([简体中文](./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 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddlespeech/server/tests/asr/online/microphone_client.py 这个文件保留