def samplePlot(fList): import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import NullFormatter # useful for `logit` scale # Fixing random state for reproducibility # plot with various axes scales plt.figure(1) i = 0 for file in fList: i += 1 print(file) plt.subplot(330 + i) signal = rd.importSignal(file) plotEach(signal) # Format the minor tick labels of the y-axis into empty strings with # `NullFormatter`, to avoid cumbering the axis with too many labels. plt.gca().yaxis.set_minor_formatter(NullFormatter()) # Adjust the subplot layout, because the logit one may take more space # than usual, due to y-tick labels like "1 - 10^{-3}" plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25, wspace=0.35) plt.show()
def execute(silences, inputFolder='./raw/', outputFolder='./train/', segment=500, verbose=True, defaultSilenceLen=defaultLen): import random as ran silences_list_len = len(silences) # number of silences sample for file in listFile(os.walk(inputFolder), ['*.wav']): org = rd.importSignal(inputFolder + file) wav, __len = trim(org, outOrgLen=True) for i in range( 1 ): # range (max ((defaultSilenceLen - __len) // segment-2, 1)): idx = ran.randrange(0, silences_list_len) choice = silences[idx] seg = mix(wav, choice, i * segment) sname = outputFolder + 'mix_%d_%d_%s' % (idx, i, file) rd.save(seg, sname) if verbose: print("Saved file:%-40s with sample size:%5d" % (sname, len(seg)))
def loadSilences(dir='./raw/silent/'): silences = [] for silent in listFile(os.walk(dir), ['*.wav']): silence = rd.importSignal('%s%s' % (dir, silent))[0:defaultLen] silences.append(silence) # print (len (silence)) return silences
def pretest(): wav1 = rd.importSignal('./raw/silent/silent0.wav')[0:defaultLen] wav2, __len = trim(rd.importSignal('./raw/như/nhu1.wav'), outOrgLen=True) wav = mix(wav2, wav1, 0) fig = plt.gcf() i = 0 seg = 1000 count = (len(wav1) - __len) // seg print(count) while 1: i = (i + 1) % count plt.clf() wav = mix(wav2, wav1, i * seg) plt.plot(wav) fig.canvas.draw() plt.pause(0.6)
def fimport(i, label): mfcc = transRaw(rd.importSignal(folder + i), trim=True) # mfcc = mfcc.reshape (defaultLen // particle, particle) # wav = processWave (rd.importSignal (folder+i)) # sd.play (wav) # sd.wait () # vz.plot (wav) # vz.show () X_train.append(mfcc) Y_train.append(label)
def check(i): from time import time wav = rd.importSignal(i) mfcc = transRaw(wav, trim=True) # have to trim a word #from time import sleep mfcc = mfcc.reshape(1, mfcc.shape[0], mfcc.shape[1]) # mfcc = mfcc.reshape (1, defaultLen // particle, particle) mark = time() pred = lobe.predict(mfcc) print('%-40s' % str(pred), 'for %10s estimate time in second: %5.4f' % (i, time() - mark), end=' ') chosen = 0 mx = 0 for i in range(len(pred[0])): if mx < pred[0][i]: chosen = i mx = pred[0][i] print('label:', chosen) return (pred[0][0] >= 0.5)
def test(): file = 'tmp.wav' signal = rd.importSignal(file) print(signal) print(type(signal)) rd.plot(signal, file)
def loadMfccFromFile(name): wav = rd.importSignal(name) return getMfcc(wav)