語言識別,語言轉文字,轉格式,自然語語言處理,圖靈操作
語言識別
from aip import AipSpeech
""" 你的 APPID AK SK """
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
# 讀取檔案
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
# 識別本地檔案
client.asr(get_file_content('audio.pcm'), 'pcm', 16000, {
'dev_pid': 1536,
})
語言轉文字
from aip import AipSpeech
""" 你的 APPID AK SK """
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis('你好百度', 'zh', 1, {
'vol': 5,
})
# 識別正確返回語音二進位制 錯誤則返回dict 參照下面錯誤碼
if not isinstance(result, dict):
with open('auido.mp3', 'wb') as f:
f.write(result)
轉格式
import os
os.system("ffmpeg -y -i wyn.wma -acodec pcm_s16le -f s16le -ac 1 -ar 16000 wyn.wma.pcm")
自然語言處理
from aip import AipNlp """ 你的 APPID AK SK """APP_ID = '15217111'
API_KEY = 'jE38mGiHGGe8LnmK2YdbGGoX'
SECRET_KEY = 'KaoFdHZoaUWQsmpRgIEgxIGhdkDbW2V4' nlp_client = AipNlp(APP_ID, API_KEY, SECRET_KEY) text1 = "你叫什麼名字" text2 = "您怎麼稱呼"
res = nlp_client.simnet(text1, text2) print(res.get("score"))#識別 自然語言處理進行對比 大於0.7的可以用
圖靈操作
"reqType":0,
"perception": {
"inputText": {
"text": "北京"
},
},
"userInfo": {
"apiKey": "c3a9ba0d958a43658a5acdcae50c13ae",
"userId": "jinwangbas"
}
}
def tl(text,uid):
data_dict["perception"]["inputText"]["text"] = text
data_dict["userInfo"]["userId"] = uid
res = requests.post(url,json=data_dict)
res_json = res.json()
return res_json.get("results")[0]["values"]["text"] #獲取想要的資料