Esempio n. 1
0
        raw_data_select += raw_data[dom[0] * 256 * 2:dom[1] * 256 * 2]

    file_en = wave.open("./temp_sound/input_voice.wav", "wb")
    file_en.setnchannels(1)
    file_en.setsampwidth(2)
    file_en.setframerate(16000)
    file_en.writeframes(raw_data_select)
    file_en.close()


##main
if __name__ == '__main__':
    order_text = ['开门', '关门', '打开', '关闭', '安静']
    #训练
    #datas = get_mfc_data('C:/Users/18341/Desktop/book/听觉/实验3-语音识别/语料/features/')
    datas = get_mfc_data('F:/HIT/大三上/视听觉/lab3/组/gzx_sound_mfcc/')

    #model = hmm.GaussianHMM(n_components = 5, n_iter = 20, tol = 0.01, covariance_type="diag")

    hmms = dict()

    for category in datas:
        Qs = datas[category]
        n_hidden = 6
        model = hmm.GaussianHMM(n_components=5,
                                n_iter=20,
                                tol=0.01,
                                covariance_type="diag")
        vstack_Qs = np.vstack(tuple(Qs[:-3]))
        #print(tuple(Qs[:-3]))
        #print('----------')
Esempio n. 2
0
import numpy as np
from hmmlearn import hmm
from get_mfc_data import get_mfc_data
import struct
import numpy as np
import os

if __name__ == "__main__":
    datas = get_mfc_data(
        'C:/Users/18341/Desktop/book/听觉/实验3-语音识别/语料/features/')

    hmms = dict()
    for category in datas:
        Qs = datas[category]
        n_hidden = 6
        model = hmm.GaussianHMM(n_components=5,
                                n_iter=5,
                                tol=0.01,
                                covariance_type="diag")
        vstack_Qs = np.vstack(tuple(Qs[:-3]))
        model.fit(vstack_Qs, [Q.shape[0] for Q in Qs[:-3]])
        print('success fit')
        hmms[category] = model

    #test
    correct_num = 0
    for category in datas:
        for test_sample in datas[category][-3:]:
            print('real_category:', category)
            max_score = -1 * np.inf
            predict = -1