from aip import AipSpeech 文件格式转换(os)+翻译成文字(原流001010)+提取有效信息文段+利用相似度(simnet)人工制定答案
+将答案与voice合成音频写入mp3 from aip import AipNlp import os #lsi模型 App_ID="11520823" API_Key="MkDwZfZz0hFuCBWsungxl0sv" Secret_Key="RjE8ywaQT2x5NGHzeN9FbHSZGefzBTCR" client=AipSpeech(App_ID,API_Key,Secret_Key)#通行证 nlp_client=AipNlp(App_ID,API_Key,Secret_Key) cmd="ffmpeg -y -i %s -acodec pcm_s16le -f s16le -ac 1 -ar 16000 %s"%( "LLL.wma", "LLLS.pcm" ) os.system(cmd) voice=None with open("LLLS.pcm", 'rb') as fp: #.pcm相当于一种流文件 liu= fp.read()#读出.pcm文件里的内容 # 将上面读取的流,识别成本地文件类似于.txt restxt=client.asr(liu, 'pcm', 16000, {#将读出的.pcm内容识别成词典 'dev_pid': 1536,#输入法模型 ,标准普通话1536,带有英文识别,比较差劲的 }) my_text="" if restxt.get("result"): my_text=restxt["result"][0] Q1="你的名字是什么" Q2="你的偶像是谁" answer="我不知道你在说什么" if nlp_client.simnet(Q1,my_text).get("score")>=0.7: answer="我的名字是美丽" if nlp_client.simnet(Q2,my_text).get("score")>=0.7: answer="林俊杰" my_voice={ "per":4, "spd":3, "pit":8, "vol":10 } print(answer) #client=AipSpeech(App_ID,API_Key,Secret_Key)#通行证 sysvoice=client.synthesis(answer,"zh",1,my_voice) print(sysvoice) with open("LLLS.mp3","wb") as f: f.write(sysvoice)