FreeSWITCH 1.10.10 Simple graphical interface 5 - using Baidu TTS

0. Interface preview

http://myfs.f3322.net:8020/Username
: admin, Password: admin

FreeSWITCH interface installation reference: https://blog.csdn.net/jia198810/article/details/132479324


In the past, I used the url link provided by Baidu to directly use get to perform TTS. It seems that Baidu TTS free interface cannot be obtained. Try using Baidu SDK to perform TTS. It is not free, and new users will receive free credits.

1. Register on Baidu AI open platform and activate speech recognition service

Insert image description here

2. Get AppID/API Key/Secret Key

As shown below:
Insert image description here

3. Install Baidu speech synthesis sdk

Baidu Help: https://ai.baidu.com/ai-doc/SPEECH/0lbxfnc9bInstall
python sdk

pip install baidu-aip-sdk
pip install baidu-aip

4. Synthetic code

from aip import AipSpeech
filename="tts.mp3"
""" 你的 APPID AK SK """
tts_engine=dict(app_id="百度appid",api_key="百度api_key",secret_key="百度secret_key")
APP_ID = tts_engine["app_id"]
API_KEY = tts_engine["api_key"]
SECRET_KEY = tts_engine["secret_key"]
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
res = client.synthesis(data.text, 'zh', 1, {
    
    'vol': 5})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(res, dict):
    with open(filename, 'wb') as f:
        f.write(res)
# 简单判断一下结果是不是音频
mime_type, encoding = mimetypes.guess_type(filename)
print(f"TTS文件是:{
      
      mime_type}")
if not mime_type.startswith("audio"):
    print("转换失败")
else:
    print("转换成功")

5. Use Baidu TTS in PBX

Click PBX Settings-TTS Engine-Add Baidu TTS, with the highest priority, as shown below:
Insert image description here
Insert image description here

6. Music files-TTS

Click PBX Settings-Music File-TTS in turn, enter the text to be converted, and perform TTS, as shown below:
Insert image description here

7. Dial rule-tts_command

In the dialing rule, use the speak application to play text, as shown below:

Insert image description here

Guess you like

Origin blog.csdn.net/jia198810/article/details/132521379