README_cn.md 8.1 KB
Newer Older
L
lym0302 已提交
1 2 3 4 5 6 7 8 9 10 11 12
([简体中文](./README_cn.md)|English)

# 语音服务

## 介绍
这个demo是一个启动语音服务和访问服务的实现。 它可以通过使用`paddlespeech_server``paddlespeech_client`的单个命令或 python 的几行代码来实现。


## 使用方法
### 1. 安装
请看 [安装文档](https://github.com/PaddlePaddle/PaddleSpeech/blob/develop/docs/source/install.md).

L
lym0302 已提交
13
推荐使用 **paddlepaddle 2.2.1** 或以上版本。
L
lym0302 已提交
14
你可以从 medium,hard 三中方式中选择一种方式安装 PaddleSpeech。
L
lym0302 已提交
15

L
lym0302 已提交
16

L
lym0302 已提交
17
### 2. 准备配置文件
L
lym0302 已提交
18 19 20 21 22
配置文件可参见 `conf/application.yaml`
其中,`engine_list`表示即将启动的服务将会包含的语音引擎,格式为 <语音任务>_<引擎类型>
目前服务集成的语音任务有: asr(语音识别)、tts(语音合成)。
目前引擎类型支持两种形式:python 及 inference (Paddle Inference)

L
lym0302 已提交
23

L
lym0302 已提交
24 25 26 27 28 29 30
这个 ASR client 的输入应该是一个 WAV 文件(`.wav`),并且采样率必须与模型的采样率相同。

可以下载此 ASR client的示例音频:
```bash
wget -c https://paddlespeech.bj.bcebos.com/PaddleAudio/zh.wav https://paddlespeech.bj.bcebos.com/PaddleAudio/en.wav
```

L
lym0302 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
### 3. 服务端使用方法
- 命令行 (推荐使用)

  ```bash
  # 启动服务
  paddlespeech_server start --config_file ./conf/application.yaml
  ```

  使用方法:
  
  ```bash
  paddlespeech_server start --help
  ```
  参数:
  - `config_file`: 服务的配置文件,默认: ./conf/application.yaml
  - `log_file`: log 文件. 默认:./log/paddlespeech.log

  输出:
  ```bash
  [2022-02-23 11:17:32] [INFO] [server.py:64] Started server process [6384]
  INFO:     Waiting for application startup.
  [2022-02-23 11:17:32] [INFO] [on.py:26] Waiting for application startup.
  INFO:     Application startup complete.
  [2022-02-23 11:17:32] [INFO] [on.py:38] Application startup complete.
  INFO:     Uvicorn running on http://0.0.0.0:8090 (Press CTRL+C to quit)
  [2022-02-23 11:17:32] [INFO] [server.py:204] Uvicorn running on http://0.0.0.0:8090 (Press CTRL+C to quit)

  ```

- Python API
  ```python
  from paddlespeech.server.bin.paddlespeech_server import ServerExecutor

  server_executor = ServerExecutor()
  server_executor(
      config_file="./conf/application.yaml", 
      log_file="./log/paddlespeech.log")
  ```

  输出:
  ```bash
  INFO:     Started server process [529]
  [2022-02-23 14:57:56] [INFO] [server.py:64] Started server process [529]
  INFO:     Waiting for application startup.
  [2022-02-23 14:57:56] [INFO] [on.py:26] Waiting for application startup.
  INFO:     Application startup complete.
  [2022-02-23 14:57:56] [INFO] [on.py:38] Application startup complete.
  INFO:     Uvicorn running on http://0.0.0.0:8090 (Press CTRL+C to quit)
  [2022-02-23 14:57:56] [INFO] [server.py:204] Uvicorn running on http://0.0.0.0:8090 (Press CTRL+C to quit)

  ```

L
lym0302 已提交
83
### 4. ASR 客户端使用方法
小湉湉's avatar
小湉湉 已提交
84
**注意:** 初次使用客户端时响应时间会略长
L
lym0302 已提交
85 86
- 命令行 (推荐使用)
   ```
L
lym0302 已提交
87
   paddlespeech_client asr --server_ip 127.0.0.1 --port 8090 --input ./zh.wav
L
lym0302 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
   ```

    使用帮助:
  
    ```bash
    paddlespeech_client asr --help
    ```

    参数:
    - `server_ip`: 服务端ip地址,默认: 127.0.0.1。
    - `port`: 服务端口,默认: 8090。
    - `input`(必须输入): 用于识别的音频文件。
    - `sample_rate`: 音频采样率,默认值:16000。
    - `lang`: 模型语言,默认值:zh_cn。
    - `audio_format`: 音频格式,默认值:wav。

    输出:

    ```bash
L
lym0302 已提交
107 108
    [2022-02-23 18:11:22,819] [    INFO] - {'success': True, 'code': 200, 'message': {'description': 'success'}, 'result': {'transcription': '我认为跑步最重要的就是给我带来了身体健康'}}
    [2022-02-23 18:11:22,820] [    INFO] - time cost 0.689145 s.
L
lym0302 已提交
109 110 111 112 113
    ```

- Python API
  ```python
  from paddlespeech.server.bin.paddlespeech_client import ASRClientExecutor
L
lym0302 已提交
114
  import json
L
lym0302 已提交
115 116

  asrclient_executor = ASRClientExecutor()
L
lym0302 已提交
117
  res = asrclient_executor(
L
lym0302 已提交
118
      input="./zh.wav",
L
lym0302 已提交
119 120 121 122 123
      server_ip="127.0.0.1",
      port=8090,
      sample_rate=16000,
      lang="zh_cn",
      audio_format="wav")
L
lym0302 已提交
124
  print(res.json())
L
lym0302 已提交
125 126 127 128
  ```

  输出:
  ```bash
L
lym0302 已提交
129
  {'success': True, 'code': 200, 'message': {'description': 'success'}, 'result': {'transcription': '我认为跑步最重要的就是给我带来了身体健康'}}
L
lym0302 已提交
130 131 132

  ```
 
L
lym0302 已提交
133
### 5. TTS 客户端使用方法
小湉湉's avatar
小湉湉 已提交
134
**注意:** 初次使用客户端时响应时间会略长
小湉湉's avatar
小湉湉 已提交
135 136 137 138 139
- 命令行 (推荐使用)

    ```bash
    paddlespeech_client tts --server_ip 127.0.0.1 --port 8090 --input "您好,欢迎使用百度飞桨语音合成服务。" --output output.wav
    ```
L
lym0302 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153
    使用帮助:
  
    ```bash
    paddlespeech_client tts --help
    ```

    参数:
    - `server_ip`: 服务端ip地址,默认: 127.0.0.1。
    - `port`: 服务端口,默认: 8090。
    - `input`(必须输入): 待合成的文本。
    - `spk_id`: 说话人 id,用于多说话人语音合成,默认值: 0。
    - `speed`: 音频速度,该值应设置在 0 到 3 之间。 默认值:1.0
    - `volume`: 音频音量,该值应设置在 0 到 3 之间。 默认值: 1.0
    - `sample_rate`: 采样率,可选 [0, 8000, 16000],默认与模型相同。 默认值:0
L
lym0302 已提交
154
    - `output`: 输出音频的路径, 默认值:None,表示不保存音频到本地。
L
lym0302 已提交
155 156 157 158 159 160 161 162 163 164 165 166

    输出:
    ```bash
    [2022-02-23 15:20:37,875] [    INFO] - {'description': 'success.'}
    [2022-02-23 15:20:37,875] [    INFO] - Save synthesized audio successfully on output.wav.
    [2022-02-23 15:20:37,875] [    INFO] - Audio duration: 3.612500 s.
    [2022-02-23 15:20:37,875] [    INFO] - Response time: 0.348050 s.
    ```

- Python API
  ```python
  from paddlespeech.server.bin.paddlespeech_client import TTSClientExecutor
L
lym0302 已提交
167
  import json
L
lym0302 已提交
168 169

  ttsclient_executor = TTSClientExecutor()
L
lym0302 已提交
170
  res = ttsclient_executor(
L
lym0302 已提交
171 172 173 174 175 176 177 178
      input="您好,欢迎使用百度飞桨语音合成服务。",
      server_ip="127.0.0.1",
      port=8090,
      spk_id=0,
      speed=1.0,
      volume=1.0,
      sample_rate=0,
      output="./output.wav")
L
lym0302 已提交
179 180 181 182 183

  response_dict = res.json()
  print(response_dict["message"])
  print("Save synthesized audio successfully on %s." % (response_dict['result']['save_path']))
  print("Audio duration: %f s." %(response_dict['result']['duration']))
L
lym0302 已提交
184 185 186 187 188 189 190 191 192 193
  ```

  输出:
  ```bash
  {'description': 'success.'}
  Save synthesized audio successfully on ./output.wav.
  Audio duration: 3.612500 s.

  ```

L
lym0302 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
  ### 5. CLS 客户端使用方法
  **注意:** 初次使用客户端时响应时间会略长
  - 命令行 (推荐使用)
   ```
   paddlespeech_client cls --server_ip 127.0.0.1 --port 8090 --input ./zh.wav
   ```

  使用帮助:
  
  ```bash
  paddlespeech_client cls --help
  ```
  参数:
  - `server_ip`: 服务端ip地址,默认: 127.0.0.1。
  - `port`: 服务端口,默认: 8090。
  - `input`(必须输入): 用于分类的音频文件。
  - `topk`: 分类结果的topk。

  输出:
  ```bash
  [2022-03-09 20:44:39,974] [    INFO] - {'success': True, 'code': 200, 'message': {'description': 'success'}, 'result': {'topk': 1, 'results': [{'class_name': 'Speech', 'prob': 0.9027184844017029}]}}
  [2022-03-09 20:44:39,975] [    INFO] - Response time 0.104360 s.


  ```

- Python API
  ```python
  from paddlespeech.server.bin.paddlespeech_client import CLSClientExecutor
L
lym0302 已提交
223
  import json
L
lym0302 已提交
224 225

  clsclient_executor = CLSClientExecutor()
L
lym0302 已提交
226
  res = clsclient_executor(
L
lym0302 已提交
227 228 229 230
      input="./zh.wav",
      server_ip="127.0.0.1",
      port=8090,
      topk=1)
L
lym0302 已提交
231
  print(res.jaon())
L
lym0302 已提交
232 233 234 235 236 237 238 239 240 241

  ```

  输出:
  ```bash
  {'success': True, 'code': 200, 'message': {'description': 'success'}, 'result': {'topk': 1, 'results': [{'class_name': 'Speech', 'prob': 0.9027184844017029}]}}

  ```


L
lym0302 已提交
242 243 244 245 246 247
## 服务支持的模型
### ASR支持的模型
通过 `paddlespeech_server stats --task asr` 获取ASR服务支持的所有模型,其中静态模型可用于 paddle inference 推理。 

### TTS支持的模型
通过 `paddlespeech_server stats --task tts` 获取TTS服务支持的所有模型,其中静态模型可用于 paddle inference 推理。
L
lym0302 已提交
248 249 250

### CLS支持的模型
通过 `paddlespeech_server stats --task cls` 获取CLS服务支持的所有模型,其中静态模型可用于 paddle inference 推理。