commit
e7a35485e4
@ -0,0 +1,52 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
pretrained_models = {
|
||||||
|
"deepspeech2online_aishell-zh-16k": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/s2t/aishell/asr0/asr0_deepspeech2_online_aishell_fbank161_ckpt_0.2.1.model.tar.gz',
|
||||||
|
'md5':
|
||||||
|
'98b87b171b7240b7cae6e07d8d0bc9be',
|
||||||
|
'cfg_path':
|
||||||
|
'model.yaml',
|
||||||
|
'ckpt_path':
|
||||||
|
'exp/deepspeech2_online/checkpoints/avg_1',
|
||||||
|
'model':
|
||||||
|
'exp/deepspeech2_online/checkpoints/avg_1.jit.pdmodel',
|
||||||
|
'params':
|
||||||
|
'exp/deepspeech2_online/checkpoints/avg_1.jit.pdiparams',
|
||||||
|
'lm_url':
|
||||||
|
'https://deepspeech.bj.bcebos.com/zh_lm/zh_giga.no_cna_cmn.prune01244.klm',
|
||||||
|
'lm_md5':
|
||||||
|
'29e02312deb2e59b3c8686c7966d4fe3'
|
||||||
|
},
|
||||||
|
"conformer_online_multicn-zh-16k": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/s2t/multi_cn/asr1/asr1_chunk_conformer_multi_cn_ckpt_0.2.3.model.tar.gz',
|
||||||
|
'md5':
|
||||||
|
'0ac93d390552336f2a906aec9e33c5fa',
|
||||||
|
'cfg_path':
|
||||||
|
'model.yaml',
|
||||||
|
'ckpt_path':
|
||||||
|
'exp/chunk_conformer/checkpoints/multi_cn',
|
||||||
|
'model':
|
||||||
|
'exp/chunk_conformer/checkpoints/multi_cn.pdparams',
|
||||||
|
'params':
|
||||||
|
'exp/chunk_conformer/checkpoints/multi_cn.pdparams',
|
||||||
|
'lm_url':
|
||||||
|
'https://deepspeech.bj.bcebos.com/zh_lm/zh_giga.no_cna_cmn.prune01244.klm',
|
||||||
|
'lm_md5':
|
||||||
|
'29e02312deb2e59b3c8686c7966d4fe3'
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
pretrained_models = {
|
||||||
|
"deepspeech2offline_aishell-zh-16k": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/s2t/aishell/asr0/asr0_deepspeech2_aishell_ckpt_0.1.1.model.tar.gz',
|
||||||
|
'md5':
|
||||||
|
'932c3593d62fe5c741b59b31318aa314',
|
||||||
|
'cfg_path':
|
||||||
|
'model.yaml',
|
||||||
|
'ckpt_path':
|
||||||
|
'exp/deepspeech2/checkpoints/avg_1',
|
||||||
|
'model':
|
||||||
|
'exp/deepspeech2/checkpoints/avg_1.jit.pdmodel',
|
||||||
|
'params':
|
||||||
|
'exp/deepspeech2/checkpoints/avg_1.jit.pdiparams',
|
||||||
|
'lm_url':
|
||||||
|
'https://deepspeech.bj.bcebos.com/zh_lm/zh_giga.no_cna_cmn.prune01244.klm',
|
||||||
|
'lm_md5':
|
||||||
|
'29e02312deb2e59b3c8686c7966d4fe3'
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
pretrained_models = {
|
||||||
|
"panns_cnn6-32k": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/cls/inference_model/panns_cnn6_static.tar.gz',
|
||||||
|
'md5':
|
||||||
|
'da087c31046d23281d8ec5188c1967da',
|
||||||
|
'cfg_path':
|
||||||
|
'panns.yaml',
|
||||||
|
'model_path':
|
||||||
|
'inference.pdmodel',
|
||||||
|
'params_path':
|
||||||
|
'inference.pdiparams',
|
||||||
|
'label_file':
|
||||||
|
'audioset_labels.txt',
|
||||||
|
},
|
||||||
|
"panns_cnn10-32k": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/cls/inference_model/panns_cnn10_static.tar.gz',
|
||||||
|
'md5':
|
||||||
|
'5460cc6eafbfaf0f261cc75b90284ae1',
|
||||||
|
'cfg_path':
|
||||||
|
'panns.yaml',
|
||||||
|
'model_path':
|
||||||
|
'inference.pdmodel',
|
||||||
|
'params_path':
|
||||||
|
'inference.pdiparams',
|
||||||
|
'label_file':
|
||||||
|
'audioset_labels.txt',
|
||||||
|
},
|
||||||
|
"panns_cnn14-32k": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/cls/inference_model/panns_cnn14_static.tar.gz',
|
||||||
|
'md5':
|
||||||
|
'ccc80b194821274da79466862b2ab00f',
|
||||||
|
'cfg_path':
|
||||||
|
'panns.yaml',
|
||||||
|
'model_path':
|
||||||
|
'inference.pdmodel',
|
||||||
|
'params_path':
|
||||||
|
'inference.pdiparams',
|
||||||
|
'label_file':
|
||||||
|
'audioset_labels.txt',
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
# 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.
|
||||||
|
# support online model
|
||||||
|
pretrained_models = {
|
||||||
|
# fastspeech2
|
||||||
|
"fastspeech2_csmsc_onnx-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/fastspeech2/fastspeech2_csmsc_onnx_0.2.0.zip',
|
||||||
|
'md5':
|
||||||
|
'fd3ad38d83273ad51f0ea4f4abf3ab4e',
|
||||||
|
'ckpt': ['fastspeech2_csmsc.onnx'],
|
||||||
|
'phones_dict':
|
||||||
|
'phone_id_map.txt',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
"fastspeech2_cnndecoder_csmsc_onnx-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/fastspeech2/fastspeech2_cnndecoder_csmsc_streaming_onnx_1.0.0.zip',
|
||||||
|
'md5':
|
||||||
|
'5f70e1a6bcd29d72d54e7931aa86f266',
|
||||||
|
'ckpt': [
|
||||||
|
'fastspeech2_csmsc_am_encoder_infer.onnx',
|
||||||
|
'fastspeech2_csmsc_am_decoder.onnx',
|
||||||
|
'fastspeech2_csmsc_am_postnet.onnx',
|
||||||
|
],
|
||||||
|
'speech_stats':
|
||||||
|
'speech_stats.npy',
|
||||||
|
'phones_dict':
|
||||||
|
'phone_id_map.txt',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
|
||||||
|
# mb_melgan
|
||||||
|
"mb_melgan_csmsc_onnx-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/mb_melgan/mb_melgan_csmsc_onnx_0.2.0.zip',
|
||||||
|
'md5':
|
||||||
|
'5b83ec746e8414bc29032d954ffd07ec',
|
||||||
|
'ckpt':
|
||||||
|
'mb_melgan_csmsc.onnx',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
|
||||||
|
# hifigan
|
||||||
|
"hifigan_csmsc_onnx-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/hifigan/hifigan_csmsc_onnx_0.2.0.zip',
|
||||||
|
'md5':
|
||||||
|
'1a7dc0385875889e46952e50c0994a6b',
|
||||||
|
'ckpt':
|
||||||
|
'hifigan_csmsc.onnx',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
# 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.
|
||||||
|
# support online model
|
||||||
|
pretrained_models = {
|
||||||
|
# fastspeech2
|
||||||
|
"fastspeech2_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/fastspeech2/fastspeech2_nosil_baker_ckpt_0.4.zip',
|
||||||
|
'md5':
|
||||||
|
'637d28a5e53aa60275612ba4393d5f22',
|
||||||
|
'config':
|
||||||
|
'default.yaml',
|
||||||
|
'ckpt':
|
||||||
|
'snapshot_iter_76000.pdz',
|
||||||
|
'speech_stats':
|
||||||
|
'speech_stats.npy',
|
||||||
|
'phones_dict':
|
||||||
|
'phone_id_map.txt',
|
||||||
|
},
|
||||||
|
"fastspeech2_cnndecoder_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/fastspeech2/fastspeech2_cnndecoder_csmsc_ckpt_1.0.0.zip',
|
||||||
|
'md5':
|
||||||
|
'6eb28e22ace73e0ebe7845f86478f89f',
|
||||||
|
'config':
|
||||||
|
'cnndecoder.yaml',
|
||||||
|
'ckpt':
|
||||||
|
'snapshot_iter_153000.pdz',
|
||||||
|
'speech_stats':
|
||||||
|
'speech_stats.npy',
|
||||||
|
'phones_dict':
|
||||||
|
'phone_id_map.txt',
|
||||||
|
},
|
||||||
|
|
||||||
|
# mb_melgan
|
||||||
|
"mb_melgan_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/mb_melgan/mb_melgan_csmsc_ckpt_0.1.1.zip',
|
||||||
|
'md5':
|
||||||
|
'ee5f0604e20091f0d495b6ec4618b90d',
|
||||||
|
'config':
|
||||||
|
'default.yaml',
|
||||||
|
'ckpt':
|
||||||
|
'snapshot_iter_1000000.pdz',
|
||||||
|
'speech_stats':
|
||||||
|
'feats_stats.npy',
|
||||||
|
},
|
||||||
|
|
||||||
|
# hifigan
|
||||||
|
"hifigan_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/hifigan/hifigan_csmsc_ckpt_0.1.1.zip',
|
||||||
|
'md5':
|
||||||
|
'dd40a3d88dfcf64513fba2f0f961ada6',
|
||||||
|
'config':
|
||||||
|
'default.yaml',
|
||||||
|
'ckpt':
|
||||||
|
'snapshot_iter_2500000.pdz',
|
||||||
|
'speech_stats':
|
||||||
|
'feats_stats.npy',
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
# 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.
|
||||||
|
# Static model applied on paddle inference
|
||||||
|
pretrained_models = {
|
||||||
|
# speedyspeech
|
||||||
|
"speedyspeech_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/speedyspeech/speedyspeech_nosil_baker_static_0.5.zip',
|
||||||
|
'md5':
|
||||||
|
'f10cbdedf47dc7a9668d2264494e1823',
|
||||||
|
'model':
|
||||||
|
'speedyspeech_csmsc.pdmodel',
|
||||||
|
'params':
|
||||||
|
'speedyspeech_csmsc.pdiparams',
|
||||||
|
'phones_dict':
|
||||||
|
'phone_id_map.txt',
|
||||||
|
'tones_dict':
|
||||||
|
'tone_id_map.txt',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
# fastspeech2
|
||||||
|
"fastspeech2_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/fastspeech2/fastspeech2_nosil_baker_static_0.4.zip',
|
||||||
|
'md5':
|
||||||
|
'9788cd9745e14c7a5d12d32670b2a5a7',
|
||||||
|
'model':
|
||||||
|
'fastspeech2_csmsc.pdmodel',
|
||||||
|
'params':
|
||||||
|
'fastspeech2_csmsc.pdiparams',
|
||||||
|
'phones_dict':
|
||||||
|
'phone_id_map.txt',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
# pwgan
|
||||||
|
"pwgan_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/pwgan/pwg_baker_static_0.4.zip',
|
||||||
|
'md5':
|
||||||
|
'e3504aed9c5a290be12d1347836d2742',
|
||||||
|
'model':
|
||||||
|
'pwgan_csmsc.pdmodel',
|
||||||
|
'params':
|
||||||
|
'pwgan_csmsc.pdiparams',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
# mb_melgan
|
||||||
|
"mb_melgan_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/mb_melgan/mb_melgan_csmsc_static_0.1.1.zip',
|
||||||
|
'md5':
|
||||||
|
'ac6eee94ba483421d750433f4c3b8d36',
|
||||||
|
'model':
|
||||||
|
'mb_melgan_csmsc.pdmodel',
|
||||||
|
'params':
|
||||||
|
'mb_melgan_csmsc.pdiparams',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
# hifigan
|
||||||
|
"hifigan_csmsc-zh": {
|
||||||
|
'url':
|
||||||
|
'https://paddlespeech.bj.bcebos.com/Parakeet/released_models/hifigan/hifigan_csmsc_static_0.1.1.zip',
|
||||||
|
'md5':
|
||||||
|
'7edd8c436b3a5546b3a7cb8cff9d5a0c',
|
||||||
|
'model':
|
||||||
|
'hifigan_csmsc.pdmodel',
|
||||||
|
'params':
|
||||||
|
'hifigan_csmsc.pdiparams',
|
||||||
|
'sample_rate':
|
||||||
|
24000,
|
||||||
|
},
|
||||||
|
}
|
@ -1,100 +0,0 @@
|
|||||||
# Copyright (c) 2021 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.
|
|
||||||
import argparse
|
|
||||||
import base64
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import time
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from paddlespeech.server.utils.audio_process import pcm2wav
|
|
||||||
|
|
||||||
|
|
||||||
def save_audio(buffer, audio_path) -> bool:
|
|
||||||
if args.save_path.endswith("pcm"):
|
|
||||||
with open(args.save_path, "wb") as f:
|
|
||||||
f.write(buffer)
|
|
||||||
elif args.save_path.endswith("wav"):
|
|
||||||
with open("./tmp.pcm", "wb") as f:
|
|
||||||
f.write(buffer)
|
|
||||||
pcm2wav("./tmp.pcm", audio_path, channels=1, bits=16, sample_rate=24000)
|
|
||||||
os.system("rm ./tmp.pcm")
|
|
||||||
else:
|
|
||||||
print("Only supports saved audio format is pcm or wav")
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def test(args):
|
|
||||||
params = {
|
|
||||||
"text": args.text,
|
|
||||||
"spk_id": args.spk_id,
|
|
||||||
"speed": args.speed,
|
|
||||||
"volume": args.volume,
|
|
||||||
"sample_rate": args.sample_rate,
|
|
||||||
"save_path": ''
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer = b''
|
|
||||||
flag = 1
|
|
||||||
url = "http://" + str(args.server) + ":" + str(
|
|
||||||
args.port) + "/paddlespeech/streaming/tts"
|
|
||||||
st = time.time()
|
|
||||||
html = requests.post(url, json.dumps(params), stream=True)
|
|
||||||
for chunk in html.iter_content(chunk_size=1024):
|
|
||||||
chunk = base64.b64decode(chunk) # bytes
|
|
||||||
if flag:
|
|
||||||
first_response = time.time() - st
|
|
||||||
print(f"首包响应:{first_response} s")
|
|
||||||
flag = 0
|
|
||||||
buffer += chunk
|
|
||||||
|
|
||||||
final_response = time.time() - st
|
|
||||||
duration = len(buffer) / 2.0 / 24000
|
|
||||||
|
|
||||||
print(f"尾包响应:{final_response} s")
|
|
||||||
print(f"音频时长:{duration} s")
|
|
||||||
print(f"RTF: {final_response / duration}")
|
|
||||||
|
|
||||||
if args.save_path is not None:
|
|
||||||
if save_audio(buffer, args.save_path):
|
|
||||||
print("音频保存至:", args.save_path)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument(
|
|
||||||
'--text',
|
|
||||||
type=str,
|
|
||||||
default="您好,欢迎使用语音合成服务。",
|
|
||||||
help='A sentence to be synthesized')
|
|
||||||
parser.add_argument('--spk_id', type=int, default=0, help='Speaker id')
|
|
||||||
parser.add_argument('--speed', type=float, default=1.0, help='Audio speed')
|
|
||||||
parser.add_argument(
|
|
||||||
'--volume', type=float, default=1.0, help='Audio volume')
|
|
||||||
parser.add_argument(
|
|
||||||
'--sample_rate',
|
|
||||||
type=int,
|
|
||||||
default=0,
|
|
||||||
help='Sampling rate, the default is the same as the model')
|
|
||||||
parser.add_argument(
|
|
||||||
"--server", type=str, help="server ip", default="127.0.0.1")
|
|
||||||
parser.add_argument("--port", type=int, help="server port", default=8092)
|
|
||||||
parser.add_argument(
|
|
||||||
"--save_path", type=str, help="save audio path", default=None)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
test(args)
|
|
@ -1,126 +0,0 @@
|
|||||||
# 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.
|
|
||||||
import _thread as thread
|
|
||||||
import argparse
|
|
||||||
import base64
|
|
||||||
import json
|
|
||||||
import ssl
|
|
||||||
import time
|
|
||||||
|
|
||||||
import websocket
|
|
||||||
|
|
||||||
flag = 1
|
|
||||||
st = 0.0
|
|
||||||
all_bytes = b''
|
|
||||||
|
|
||||||
|
|
||||||
class WsParam(object):
|
|
||||||
# 初始化
|
|
||||||
def __init__(self, text, server="127.0.0.1", port=8090):
|
|
||||||
self.server = server
|
|
||||||
self.port = port
|
|
||||||
self.url = "ws://" + self.server + ":" + str(self.port) + "/ws/tts"
|
|
||||||
self.text = text
|
|
||||||
|
|
||||||
# 生成url
|
|
||||||
def create_url(self):
|
|
||||||
return self.url
|
|
||||||
|
|
||||||
|
|
||||||
def on_message(ws, message):
|
|
||||||
global flag
|
|
||||||
global st
|
|
||||||
global all_bytes
|
|
||||||
|
|
||||||
try:
|
|
||||||
message = json.loads(message)
|
|
||||||
audio = message["audio"]
|
|
||||||
audio = base64.b64decode(audio) # bytes
|
|
||||||
status = message["status"]
|
|
||||||
all_bytes += audio
|
|
||||||
|
|
||||||
if status == 0:
|
|
||||||
print("create successfully.")
|
|
||||||
elif status == 1:
|
|
||||||
if flag:
|
|
||||||
print(f"首包响应:{time.time() - st} s")
|
|
||||||
flag = 0
|
|
||||||
elif status == 2:
|
|
||||||
final_response = time.time() - st
|
|
||||||
duration = len(all_bytes) / 2.0 / 24000
|
|
||||||
print(f"尾包响应:{final_response} s")
|
|
||||||
print(f"音频时长:{duration} s")
|
|
||||||
print(f"RTF: {final_response / duration}")
|
|
||||||
with open("./out.pcm", "wb") as f:
|
|
||||||
f.write(all_bytes)
|
|
||||||
print("ws is closed")
|
|
||||||
ws.close()
|
|
||||||
else:
|
|
||||||
print("infer error")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print("receive msg,but parse exception:", e)
|
|
||||||
|
|
||||||
|
|
||||||
# 收到websocket错误的处理
|
|
||||||
def on_error(ws, error):
|
|
||||||
print("### error:", error)
|
|
||||||
|
|
||||||
|
|
||||||
# 收到websocket关闭的处理
|
|
||||||
def on_close(ws):
|
|
||||||
print("### closed ###")
|
|
||||||
|
|
||||||
|
|
||||||
# 收到websocket连接建立的处理
|
|
||||||
def on_open(ws):
|
|
||||||
def run(*args):
|
|
||||||
global st
|
|
||||||
text_base64 = str(
|
|
||||||
base64.b64encode((wsParam.text).encode('utf-8')), "UTF8")
|
|
||||||
d = {"text": text_base64}
|
|
||||||
d = json.dumps(d)
|
|
||||||
print("Start sending text data")
|
|
||||||
st = time.time()
|
|
||||||
ws.send(d)
|
|
||||||
|
|
||||||
thread.start_new_thread(run, ())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument(
|
|
||||||
"--text",
|
|
||||||
type=str,
|
|
||||||
help="A sentence to be synthesized",
|
|
||||||
default="您好,欢迎使用语音合成服务。")
|
|
||||||
parser.add_argument(
|
|
||||||
"--server", type=str, help="server ip", default="127.0.0.1")
|
|
||||||
parser.add_argument("--port", type=int, help="server port", default=8092)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
print("***************************************")
|
|
||||||
print("Server ip: ", args.server)
|
|
||||||
print("Server port: ", args.port)
|
|
||||||
print("Sentence to be synthesized: ", args.text)
|
|
||||||
print("***************************************")
|
|
||||||
|
|
||||||
wsParam = WsParam(text=args.text, server=args.server, port=args.port)
|
|
||||||
|
|
||||||
websocket.enableTrace(False)
|
|
||||||
wsUrl = wsParam.create_url()
|
|
||||||
ws = websocket.WebSocketApp(
|
|
||||||
wsUrl, on_message=on_message, on_error=on_error, on_close=on_close)
|
|
||||||
ws.on_open = on_open
|
|
||||||
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
|
|
Loading…
Reference in new issue