百度云实现语音识别及语音合成

第一步,点击人工智能,语音合成,然后立即使用:

然后再应用列表里面创建应用:

查看技术文档,下面附上我的语音合成及识别的代码:

from aip import AipSpeech

""" 你的 APPID AK SK """
APP_ID = '15079673'
API_KEY = 'mGxvq3Nwr3aVjD4UFIFGsaMD'
SECRET_KEY = 'YIN3wxizj16zCRYZ6EGpdopuA6FwHRhB'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result  = client.synthesis('欢迎入住酒店,祝您入住愉快', 'zh', 1, {
    'vol': 5,
})

# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
    with open('test.mp3', 'wb') as f:
        f.write(result)
from aip import AipSpeech
import os
""" 你的 APPID AK SK """
APP_ID = '14992590'
API_KEY = 'sMz9feVUT9DkdemD0iwsVlD8'
SECRET_KEY = 'EIKmYpTP71oKuBWuauIOZfGwwbTiRUOC'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
# 读取文件
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()
while True:
    os.system('arecord -D "plughw:1" -f S16_LE -r 16000 -d 8 voice.pcm')#录音
    # 识别本地文件
    a = client.asr(get_file_content('voice.pcm'), 'pcm', 16000, {'dev_pid': 1536,})
    #print(a)
    b=str(a['result'])
    print(b[2:-2])

猜你喜欢

转载自blog.csdn.net/weixin_38241876/article/details/84949534