百度AI


1.語音合成

1.登錄百度AI平台

選擇控制台

參考技術文檔選擇python SDK

pip install baidu-aip
from aip import AipSpeech

APP_ID = '2191211'
API_KEY = 'tQ1f7pryTnMjQMfuYGL8'
SECRET_KEY = 'M70i1KwVfYgKZLY0pvl3LKGtTYg'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

result = client.synthesis('先帝創業未半而中道崩殂', 'zh', 1,
                          {
                              'vol': 5,
                              "spd": 4,
                              "pit": 6,
                              "per": 4
                          })
# 識別正確返回語音二進制 錯誤則返回dict 參照下面錯誤碼
if not isinstance(result, dict):
    with open('aui2do.mp3', 'wb') as f:
        f.write(result)
else:
    print(result)

2.語音識別

from aip import AipSpeech

APP_ID = '21411'
API_KEY = 'tQ1f7prynKMjQMfuYGL8'
SECRET_KEY = 'M70i1KwVfYgKZpEnGvl3LKGtTYg'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

# 讀取文件
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

# 識別本地文件
res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
    'dev_pid': 1537,
})
print(res['result'][0])

3.智障對話

1.low版本

from aip import AipSpeech
import  os

APP_ID = '21911'
API_KEY = 'tQ1f7pryTnKMQMfuYGL8'
SECRET_KEY = 'M70i1KgKZYr0pE5nGvl3LKGtTYg'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

# 讀取文件
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

# 識別本地文件
res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
    'dev_pid': 1537,
})
Q = res['result'][0]
A = "我不知道"
if Q == "你的名字叫什么?":
    A = "zbb"
result = client.synthesis(A, 'zh', 1,
                          {
                              'vol': 5,
                              "spd": 4,
                              "pit": 6,
                              "per": 4
                          })

if not isinstance(result, dict):
    with open('aui2do.mp3', 'wb') as f:
        f.write(result)
else:
    print(result)

os.system("aui2do.mp3")

2.升級版

自然語言處理

from aip import AipSpeech
from aip import AipNlp
import os

APP_ID = '22411'
API_KEY = 'tQ1f7pryTnd8MfuYGL8'
SECRET_KEY = 'M70i1KwVfYK0pE5nGvl3LKGtTYg'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

nlp_client = AipNlp(APP_ID, API_KEY, SECRET_KEY)


# 讀取文件
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


# 識別本地文件
res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
    'dev_pid': 1537,
})
Q = res['result'][0]
A = "我是你爸爸"
if nlp_client.simnet(Q, "你的名字叫什么?")['score'] > 0.6:
    A = "你是我兒子"

result = client.synthesis(A, 'zh', 1,
                          {
                              'vol': 5,
                              "spd": 4,
                              "pit": 6,
                              "per": 4
                          })

if not isinstance(result, dict):
    with open('aui2do.mp3', 'wb') as f:
        f.write(result)
else:
    print(result)

os.system("aui2do.mp3")

3.加強版

問答機器人 -圖靈機器人

import requests

res = requests.post(url='http://openapi.tuling123.com/openapi/api/v2', json={
    "reqType": 0,
    "perception": {
        "inputText": {
            "text": "青島的天氣"
        },
    },
    "userInfo": {
        "apiKey": "9ea379299a91354e0fe979ad",
        "userId": "6542"
    }
})
print(res.json()['results'][0]['values']['text'])
#青島:周二 08月11日,多雲轉小雨 南風,最低氣溫25度,最高氣溫28度。~

4.進化版

from aip import AipSpeech
from aip import AipNlp
import os
import requests

APP_ID = '212411'
API_KEY = 'tQ1f7prTnd8jQMfuYGL8'
SECRET_KEY = 'M70i1KwVfYr0'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
nlp_client = AipNlp(APP_ID, API_KEY, SECRET_KEY)


# 讀取文件
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


# 識別本地文件
res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
    'dev_pid': 1537,
})
Q = res['result'][0]

if nlp_client.simnet(Q, "附近的酒單?")['score'] > 0.6:
    A = "你是我兒子"

else:
    res = requests.post(url='http://openapi.tuling123.com/openapi/api/v2', json={
        "reqType": 0,
        "perception": {
            "inputText": {
                "text": Q
            },
        },
        "userInfo": {
            "apiKey": "9ea379299354e979ad",
            "userId": "654562"
        }
    })
    A =  res.json()['results'][0]['values']['text']
result = client.synthesis(A, 'zh', 1,
                          {
                              'vol': 5,
                              "spd": 4,
                              "pit": 6,
                              "per": 4
                          })

if not isinstance(result, dict):
    with open('aui2do.mp3', 'wb') as f:
        f.write(result)
else:
    print(result)

os.system("aui2do.mp3")

5.究極版

科大訊飛 語音最強沒有之一(當然圖片識別啥的好爛。。。)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM