提交 d923a930 编写于 作者: X Xinghai Sun

Add ASR demo usage to README.md for DS2.

上级 a40c6223
...@@ -143,3 +143,19 @@ python tune.py --help ...@@ -143,3 +143,19 @@ python tune.py --help
``` ```
Then reset parameters with the tuning result before inference or evaluating. Then reset parameters with the tuning result before inference or evaluating.
### Playing with the ASR Demo
A real-time ASR demo (`demo_server.py` and `demo_client.py`) are prepared for users to try out the ASR model with their own voice. After a model and language model is prepared, we can first start the demo server:
```
CUDA_VISIBLE_DEVICES=0 python demo_server.py
```
And then in another console, start the client:
```
python demo_client.py
```
On the client console, press and hold "white-space" key and start talking, then release the "white-space" key when you finish your speech. The decoding results (infered transcription) will be displayed.
If you would like to start server and client in two machines. Please use `--host_ip` and `--host_port` to indicate the actual IP address and port, for both `demo_server.py` and `demo_client.py`.
"""Client-end for the ASR demo."""
from pynput import keyboard from pynput import keyboard
import struct import struct
import socket import socket
import sys import sys
import argparse
import pyaudio import pyaudio
HOST, PORT = "10.104.18.14", 8086 parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--host_ip",
default="localhost",
type=str,
help="Server IP address. (default: %(default)s)")
parser.add_argument(
"--host_port",
default=8086,
type=int,
help="Server Port. (default: %(default)s)")
args = parser.parse_args()
is_recording = False is_recording = False
enable_trigger_record = True enable_trigger_record = True
...@@ -42,7 +55,7 @@ def callback(in_data, frame_count, time_info, status): ...@@ -42,7 +55,7 @@ def callback(in_data, frame_count, time_info, status):
elif len(data_list) > 0: elif len(data_list) > 0:
# Connect to server and send data # Connect to server and send data
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT)) sock.connect((args.host_ip, args.host_port))
sent = ''.join(data_list) sent = ''.join(data_list)
sock.sendall(struct.pack('>i', len(sent)) + sent) sock.sendall(struct.pack('>i', len(sent)) + sent)
print('Speech[length=%d] Sent.' % len(sent)) print('Speech[length=%d] Sent.' % len(sent))
......
"""Server-end for the ASR demo."""
import os import os
import time import time
import random import random
...@@ -17,7 +18,7 @@ from data_utils.utils import read_manifest ...@@ -17,7 +18,7 @@ from data_utils.utils import read_manifest
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument( parser.add_argument(
"--host_ip", "--host_ip",
default="10.104.18.14", default="localhost",
type=str, type=str,
help="Server IP address. (default: %(default)s)") help="Server IP address. (default: %(default)s)")
parser.add_argument( parser.add_argument(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册