最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)簡(jiǎn)單的語(yǔ)音識(shí)別系統(tǒng)

 更新時(shí)間:2017年12月13日 09:36:21   作者:PYB不開(kāi)心  
這篇文章主要介紹了Python實(shí)現(xiàn)簡(jiǎn)單的語(yǔ)音識(shí)別系統(tǒng),具有一定借鑒價(jià)值,需要的朋友可以參考下。

最近認(rèn)識(shí)了一個(gè)做Python語(yǔ)音識(shí)別的朋友,聊天時(shí)候說(shuō)到,未來(lái)五到十年,Python人工智能會(huì)在國(guó)內(nèi)掀起一股狂潮,對(duì)各種應(yīng)用的沖擊,不下于淘寶對(duì)實(shí)體經(jīng)濟(jì)的沖擊。在本地(江蘇某三線城市)做這一行,短期可能顯不出效果,但從長(zhǎng)遠(yuǎn)來(lái)看,絕對(duì)是一個(gè)高明的選擇。朋友老家山東的,畢業(yè)來(lái)這里創(chuàng)業(yè),也是十分有想法啊。

將AI課上學(xué)習(xí)的知識(shí)進(jìn)行簡(jiǎn)單的整理,可以識(shí)別簡(jiǎn)單的0-9的單個(gè)語(yǔ)音?;痉椒ň褪抢脦?kù)函數(shù)提取mfcc,然后計(jì)算誤差矩陣,再利用動(dòng)態(tài)規(guī)劃計(jì)算累積矩陣。并且限制了匹配路徑的范圍。具體的技術(shù)網(wǎng)上很多,不再細(xì)談。

現(xiàn)有缺點(diǎn)就是輸入的語(yǔ)音長(zhǎng)度都是1s,如果不固定長(zhǎng)度則識(shí)別效果變差。改進(jìn)思路是提取有效語(yǔ)音部分。但是該部分尚未完全做好,只寫(xiě)了一個(gè)原形函數(shù),尚未完善。

import wave
import numpy as np
import matplotlib.pyplot as plt
from python_speech_features import mfcc
from math import cos,sin,sqrt,pi
def read_file(file_name):
  with wave.open(file_name,'r') as file:
    params = file.getparams()
    _, _, framerate, nframes = params[:4] 
    str_data = file.readframes(nframes)
    wave_data = np.fromstring(str_data, dtype = np.short)
    time = np.arange(0, nframes) * (1.0/framerate)
    return wave_data, time 
  return index1,index2
def find_point(data):
  count1,count2 = 0,0
  for index,val in enumerate(data):
    if count1 <40:
      count1 = count1+1 if abs(val)>0.15 else 0
      index1 = index
    if count1==40 and count2 <5:
      count2 = count2+1 if abs(val)<0.001 else 0
      index2 = index
    if count2==5:break
  return index1,index2
def select_valid(data):
  start,end = find_point(normalized(data))
  print(start,end)
  return data[start:end]
def normalized(a):
  maximum = max(a)
  minimum = min(a)
  return a/maximum

def compute_mfcc_coff(file_prefix = ''):
  mfcc_feats = []
  s = range(10)
  I = [0,3,4,8]
  II = [5,7,9]
  Input = {'':s,'I':I,'II':II,'B':s}
  for index,file_name in enumerate(file_prefix+'{0}.wav'.format(i) for i in Input[file_prefix]):
    data,time = read_file(file_name)
    #data = select_valid(data)
    #if file_prefix=='II':data = select_valid(data)

    mfcc_feat = mfcc(data,48000)[:75]
    mfcc_feats.append(mfcc_feat)
  t = np.array(mfcc_feats)
  return np.array(mfcc_feats)
def create_dist():

  for i,m_i in enumerate(mfcc_coff_input):#get the mfcc of input
    for j,m_j in enumerate(mfcc_coff):#get the mfcc of dataset
      #build the distortion matrix bwtween i wav and j wav
      N = len(mfcc_coff[0])
      distortion_mat = np.array([[0]*len(m_i) for i in range(N)],dtype = np.double)
      for k1,mfcc1 in enumerate(m_i):
        for k2,mfcc2 in enumerate(m_j):
          distortion_mat[k1][k2] = sqrt(sum((mfcc1[1:]-mfcc2[1:])**2))
      yield i,j,distortion_mat

def create_Dist():

  for _i,_j,dist in create_dist():
    N = len(dist)
    Dist = np.array([[0]*N for i in range(N)],dtype = np.double)
    Dist[0][0] = dist[0][0]
    for i in range(N):
      for j in range(N):
        if i|j ==0:continue
        pos = [(i-1,j),(i,j-1),(i-1,j-1)]
        Dist[i][j] = dist[i][j] + min(Dist[k1][k2] for k1,k2 in pos if k1>-1 and k2>-1)


    #if _i==0 and _j==1 :print(_i,_j,'\n',Dist,len(Dist[0]),len(Dist[1]))
    yield _i,_j,Dist
def search_path(n):
  comparison = np.array([[0]*10 for i in range(n)],dtype = np.double)
  for _i,_j,Dist in create_Dist():
    N = len(Dist)
    cut_off = 5
    row = [(d,N-1,j) for j,d in enumerate(Dist[N-1]) if abs(N-1-j)<=cut_off]
    col = [(d,i,N-1) for i,d in enumerate(Dist[:,N-1]) if abs(N-1-i)<=cut_off]
    min_d,min_i,min_j = min(row+col )
    comparison[_i][_j] = min_d
    optimal_path_x,optimal_path_y = [min_i],[min_j]
    while min_i and min_j:
      optimal_path_x.append(min_i)
      optimal_path_y.append(min_j)
      pos = [(min_i-1,min_j),(min_i,min_j-1),(min_i-1,min_j-1)]
      #try:
      min_d,min_i,min_j = min(((Dist[int(k1)][int(k2)],k1,k2) for k1,k2 in pos\
      if abs(k1-k2)<=cut_off))

    if _i==_j and _i==4:
      plt.scatter(optimal_path_x[::-1],optimal_path_y[::-1],color = 'red')
      plt.show()
  return comparison

mfcc_coff_input = []
mfcc_coff = []

def match(pre):
  global mfcc_coff_input
  global mfcc_coff
  mfcc_coff_input = compute_mfcc_coff(pre)
  compare = np.array([[0]*10 for i in range(len(mfcc_coff_input))],dtype = np.double)
  for prefix in ['','B']:
    mfcc_coff = compute_mfcc_coff(prefix)
    compare += search_path(len(mfcc_coff_input))
  for l in compare:
    print([int(x) for x in l])
    print(min(((val,index)for index,val in enumerate(l)))[1])
data,time = read_file('8.wav')
match('I')
match('II')

總結(jié)

以上就是本文關(guān)于Python實(shí)現(xiàn)簡(jiǎn)單的語(yǔ)音識(shí)別系統(tǒng)的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:

Python用戶推薦系統(tǒng)曼哈頓算法實(shí)現(xiàn)完整代碼

Python編程使用tkinter模塊實(shí)現(xiàn)計(jì)算器軟件完整代碼示例

如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!

相關(guān)文章

最新評(píng)論

元阳县| 江陵县| 教育| 巨鹿县| 峨眉山市| 蓬莱市| 呼和浩特市| 棋牌| 虞城县| 岚皋县| 华池县| 汉沽区| 新平| 仪陇县| 宁乡县| 大新县| 康定县| 池州市| 昭平县| 海口市| 张家口市| 鄂托克旗| 阿巴嘎旗| 米脂县| 广丰县| 古田县| 广河县| 定结县| 漳浦县| 乐山市| 宁远县| 武义县| 沙坪坝区| 桐庐县| 尼勒克县| 鄱阳县| 临邑县| 邢台县| 东宁县| 稻城县| 宜川县|