falsk 基礎 語音識別與語音合成()

2022-08-20 15:27:13 字數 3978 閱讀 9991

首先搜尋進入官網。

然後建立乙個語音應用:

管理應用之後:

語音合成:

然後新建乙個py檔案:

from aip import

aipspeech

14454183

'api_key = '

txnugcisenveb93i70eswwb4

'secret_key = '

dzdok3dcueuxe28atfgioqzxvd91bmqu

'res = client.synthesis('

我如果愛你

',options=)

with open(

"audio.***

",'wb

')as f:

f.write(res)

語音識別:

在本地儲存乙個音訊檔案,新建乙個py檔案:

from aip import

aipspeech

import

os14454183

'api_key = '

txnugcisenveb93i70eswwb4

'secret_key = '

dzdok3dcueuxe28atfgioqzxvd91bmqu

'def

get_file_content(filepath):

'''因為只能識別pcm格式的音訊,所以利用ffmpeg將***格式轉化成pcm格式

'''cmd_str = "

ffmpeg -y -i -acodec pcm_s16le -f s16le -ac 1 -ar 16000 .pcm

".format(filepath)

os.system(cmd_str)

with open(

"%s.pcm

"%(filepath), 'rb'

) as f:

return

f.read()

res = client.asr(speech=get_file_content("

audio.***

"),options=)

print(res)

要記得將ffpeg中的bin目錄放在系統的環境變數裡,然後重啟pycharn。

然後我們寫乙個demo:功能是實現將我們的音訊檔案讀出來。

from aip import

aipspeech

import

os14454183

'api_key = '

txnugcisenveb93i70eswwb4

'secret_key = '

dzdok3dcueuxe28atfgioqzxvd91bmqu

'def

get_file_content(filepath):

cmd_str = "

ffmpeg -y -i -acodec pcm_s16le -f s16le -ac 1 -ar 16000 .pcm

".format(filepath)

os.system(cmd_str)

with open(

"%s.pcm

"%(filepath), 'rb'

) as f:

return

f.read()

defxsh(filename):

res = client.asr(speech=get_file_content(filename), options=)

text = res.get('

result

')[0]

res =client.synthesis(

text,

options=)

with open(

"audio2.***

", 'wb'

)as f:

f.write(res)

os.system(

"audio2.***")

xsh(

'audio.***

')

自然語言:

同樣建立乙個自然語言的應用:

建立之後:

新建乙個py檔案:

from aip import

aipnlp

14457133

'api_key = '

yehip7ofhgqni7bd1r29lygh

'secret_key = '

ri0wgweyhsyqsztv4kzdrvnwv34nq2f7

'res = client.simnet('

你今年多大了?

','你的年齡是多少?')

#判斷兩句話的相似度,如果相似度大於0.72,就認為兩句話語義是一樣的

print(res)

列印結果:

判斷兩句話的相似度,如果相似度大於0.72,就認為兩句話語義是一樣的
我們寫乙個回答簡單問題的demo:

from aip import

aipspeech,aipnlp

import

os14454183

'api_key = '

txnugcisenveb93i70eswwb4

'secret_key = '

dzdok3dcueuxe28atfgioqzxvd91bmqu

'def

get_file_content(filepath):

cmd_str = "

ffmpeg -y -i -acodec pcm_s16le -f s16le -ac 1 -ar 16000 .pcm

".format(filepath)

os.system(cmd_str)

with open(

"%s.pcm

"%(filepath), 'rb'

) as f:

return

f.read()

defxsh(filename):

res = client.asr(speech=get_file_content(filename), options=)

text = res.get('

result

')[0]

text =my_nlp(text)

res =client.synthesis(

text,

options=)

with open(

"audio2.***

", 'wb'

)as f:

f.write(res)

os.system(

"audio2.***

") # 系統執行檔案

defmy_nlp(text):

if nlp_client.simnet('

你叫什麼名字?

',text).get('

score

') >= 0.72:

return

'我的名字叫金王八

'if nlp_client.simnet('

你今年幾歲了?

',text).get('

score

') >= 0.72:

return

'我今年999歲了

'xsh(

'audio.***

')

圖靈機械人:

C 語音識別(文字to語音 語音to文字)

最近打算研究一下語音識別,但是發現網上很少有c 的完整 就把自己的學習心得放上來,和大家分享一下。1 speechsdk51.exe 67.0 mb 2 speechsdk51langpack.exe 81.0 mb 文字to語音 這個相當的簡單。1 在com選項卡裡面的microsoft spee...

C 語音識別(文字to語音 語音to文字)

最近打算研究一下語音識別,但是發現網上很少有c 的完整 就把自己的學習心得放上來,和大家分享一下。1 speechsdk51.exe 67.0 mb 2 speechsdk51langpack.exe 81.0 mb 文字to語音 這個相當的簡單。1 在com選項卡裡面的microsoft spee...

語音識別基礎知識

最近學習過程中整理的語音識別的基礎知識的筆記 語音識別本質上是一種模式識別的過程,未知語音的模式與已知語音的參考模式逐一進行比較,最佳匹配的參考模式被作為識別結果。當今語音識別技術的主流演算法 主要有基於動態時間規整 dtw 演算法 基於非引數模型的向量量化 vq 方法 基於引數模型的隱馬爾可夫模型...