commit
103e46f819
@ -0,0 +1,67 @@
|
||||
([简体中文](./README_cn.md)|English)
|
||||
|
||||
# Streaming Speech Synthesis Service
|
||||
|
||||
## Introduction
|
||||
This demo is an implementation of starting the streaming speech synthesis service and accessing the service.
|
||||
|
||||
`Server` must be started in the docker, while `Client` does not have to be in the docker.
|
||||
|
||||
**The streaming_tts_serving under the path of this article ($PWD) contains the configuration and code of the model, which needs to be mapped to the docker for use.**
|
||||
|
||||
## Usage
|
||||
### 1. Server
|
||||
#### 1.1 Docker
|
||||
|
||||
```bash
|
||||
docker pull registry.baidubce.com/paddlepaddle/fastdeploy_serving_cpu_only:22.09
|
||||
docker run -dit --net=host --name fastdeploy --shm-size="1g" -v $PWD:/models registry.baidubce.com/paddlepaddle/fastdeploy_serving_cpu_only:22.09
|
||||
docker exec -it -u root fastdeploy bash
|
||||
```
|
||||
|
||||
#### 1.2 Installation(inside the docker)
|
||||
```bash
|
||||
apt-get install build-essential python3-dev libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev libsndfile1 language-pack-zh-hans wget zip
|
||||
pip3 install paddlespeech
|
||||
export LC_ALL="zh_CN.UTF-8"
|
||||
export LANG="zh_CN.UTF-8"
|
||||
export LANGUAGE="zh_CN:zh:en_US:en"
|
||||
```
|
||||
|
||||
#### 1.3 Download models(inside the docker)
|
||||
```bash
|
||||
cd /models/streaming_tts_serving/1
|
||||
wget https://paddlespeech.bj.bcebos.com/Parakeet/released_models/fastspeech2/fastspeech2_cnndecoder_csmsc_streaming_onnx_1.0.0.zip
|
||||
wget https://paddlespeech.bj.bcebos.com/Parakeet/released_models/mb_melgan/mb_melgan_csmsc_onnx_0.2.0.zip
|
||||
unzip fastspeech2_cnndecoder_csmsc_streaming_onnx_1.0.0.zip
|
||||
unzip mb_melgan_csmsc_onnx_0.2.0.zip
|
||||
```
|
||||
**For the convenience of users, we recommend that you use the command `docker -v` to map $PWD (streaming_tts_service and the configuration and code of the model contained therein) to the docker path `/models`. You can also use other methods, but regardless of which method you use, the final model directory and structure in the docker are shown in the following figure.**
|
||||
|
||||
<p align="center">
|
||||
<img src="./tree.png" />
|
||||
</p>
|
||||
|
||||
#### 1.4 Start the server(inside the docker)
|
||||
|
||||
```bash
|
||||
fastdeployserver --model-repository=/models --model-control-mode=explicit --load-model=streaming_tts_serving
|
||||
```
|
||||
Arguments:
|
||||
- `model-repository`(required): Path of model storage.
|
||||
- `model-control-mode`(required): The mode of loading the model. At present, you can use 'explicit'.
|
||||
- `load-model`(required): Name of the model to be loaded.
|
||||
- `http-port`(optional): Port for http service. Default: `8000`. This is not used in our example.
|
||||
- `grpc-port`(optional): Port for grpc service. Default: `8001`.
|
||||
- `metrics-port`(optional): Port for metrics service. Default: `8002`. This is not used in our example.
|
||||
|
||||
### 2. Client
|
||||
#### 2.1 Installation
|
||||
```bash
|
||||
pip3 install tritonclient[all]
|
||||
```
|
||||
|
||||
#### 2.2 Send request
|
||||
```bash
|
||||
python3 /models/streaming_tts_serving/stream_client.py
|
||||
```
|
@ -0,0 +1,33 @@
|
||||
name: "streaming_tts_serving"
|
||||
backend: "python"
|
||||
max_batch_size: 0
|
||||
model_transaction_policy {
|
||||
decoupled: True
|
||||
}
|
||||
input [
|
||||
{
|
||||
name: "INPUT_0"
|
||||
data_type: TYPE_STRING
|
||||
dims: [ 1 ]
|
||||
}
|
||||
]
|
||||
|
||||
output [
|
||||
{
|
||||
name: "OUTPUT_0"
|
||||
data_type: TYPE_FP32
|
||||
dims: [ -1, 1 ]
|
||||
},
|
||||
{
|
||||
name: "status"
|
||||
data_type: TYPE_BOOL
|
||||
dims: [ 1 ]
|
||||
}
|
||||
]
|
||||
|
||||
instance_group [
|
||||
{
|
||||
count: 1
|
||||
kind: KIND_CPU
|
||||
}
|
||||
]
|
@ -0,0 +1,117 @@
|
||||
#!/usr/bin/env python
|
||||
import argparse
|
||||
import queue
|
||||
import sys
|
||||
from functools import partial
|
||||
|
||||
import numpy as np
|
||||
import tritonclient.grpc as grpcclient
|
||||
from tritonclient.utils import *
|
||||
|
||||
FLAGS = None
|
||||
|
||||
|
||||
class UserData:
|
||||
def __init__(self):
|
||||
self._completed_requests = queue.Queue()
|
||||
|
||||
|
||||
# Define the callback function. Note the last two parameters should be
|
||||
# result and error. InferenceServerClient would povide the results of an
|
||||
# inference as grpcclient.InferResult in result. For successful
|
||||
# inference, error will be None, otherwise it will be an object of
|
||||
# tritonclientutils.InferenceServerException holding the error details
|
||||
def callback(user_data, result, error):
|
||||
if error:
|
||||
user_data._completed_requests.put(error)
|
||||
else:
|
||||
user_data._completed_requests.put(result)
|
||||
|
||||
|
||||
def async_stream_send(triton_client, values, request_id, model_name):
|
||||
|
||||
infer_inputs = []
|
||||
outputs = []
|
||||
for idx, data in enumerate(values):
|
||||
data = np.array([data.encode('utf-8')], dtype=np.object_)
|
||||
infer_input = grpcclient.InferInput('INPUT_0', [len(data)], "BYTES")
|
||||
infer_input.set_data_from_numpy(data)
|
||||
infer_inputs.append(infer_input)
|
||||
|
||||
outputs.append(grpcclient.InferRequestedOutput('OUTPUT_0'))
|
||||
# Issue the asynchronous sequence inference.
|
||||
triton_client.async_stream_infer(
|
||||
model_name=model_name,
|
||||
inputs=infer_inputs,
|
||||
outputs=outputs,
|
||||
request_id=request_id)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'-v',
|
||||
'--verbose',
|
||||
action="store_true",
|
||||
required=False,
|
||||
default=False,
|
||||
help='Enable verbose output')
|
||||
parser.add_argument(
|
||||
'-u',
|
||||
'--url',
|
||||
type=str,
|
||||
required=False,
|
||||
default='localhost:8001',
|
||||
help='Inference server URL and it gRPC port. Default is localhost:8001.')
|
||||
|
||||
FLAGS = parser.parse_args()
|
||||
|
||||
# We use custom "sequence" models which take 1 input
|
||||
# value. The output is the accumulated value of the inputs. See
|
||||
# src/custom/sequence.
|
||||
model_name = "streaming_tts_serving"
|
||||
|
||||
values = ["哈哈哈哈"]
|
||||
|
||||
request_id = "0"
|
||||
|
||||
string_result0_list = []
|
||||
|
||||
user_data = UserData()
|
||||
|
||||
# It is advisable to use client object within with..as clause
|
||||
# when sending streaming requests. This ensures the client
|
||||
# is closed when the block inside with exits.
|
||||
with grpcclient.InferenceServerClient(
|
||||
url=FLAGS.url, verbose=FLAGS.verbose) as triton_client:
|
||||
try:
|
||||
# Establish stream
|
||||
triton_client.start_stream(callback=partial(callback, user_data))
|
||||
# Now send the inference sequences...
|
||||
async_stream_send(triton_client, values, request_id, model_name)
|
||||
except InferenceServerException as error:
|
||||
print(error)
|
||||
sys.exit(1)
|
||||
|
||||
# Retrieve results...
|
||||
recv_count = 0
|
||||
result_dict = {}
|
||||
status = True
|
||||
while True:
|
||||
data_item = user_data._completed_requests.get()
|
||||
if type(data_item) == InferenceServerException:
|
||||
raise data_item
|
||||
else:
|
||||
this_id = data_item.get_response().id
|
||||
if this_id not in result_dict.keys():
|
||||
result_dict[this_id] = []
|
||||
result_dict[this_id].append((recv_count, data_item))
|
||||
sub_wav = data_item.as_numpy('OUTPUT_0')
|
||||
status = data_item.as_numpy('status')
|
||||
print('sub_wav = ', sub_wav, "subwav.shape = ", sub_wav.shape)
|
||||
print('status = ', status)
|
||||
if status[0] == 1:
|
||||
break
|
||||
recv_count += 1
|
||||
|
||||
print("PASS: stream_client")
|
After Width: | Height: | Size: 24 KiB |
Loading…
Reference in new issue