def record_process(recordFile, logFile, channelNum, sampleRate, sampleWidth, littleEndian): speech_process.speech_process(recordFile, nchannels=channelNum, sampleRate=sampleRate, sampleWidth=sampleWidth, littleEndian=littleEndian, logFile=logFile)
def make_mixture(data, tr_tst, t_max, noisex_path, noise_type, snr, sample_rate, LC, frameLen, n_fft, hop_length, win_length, nfilt): Frame_numb = [] noisex = noisex_path + '/' + noise_type + '.wav' noise, sr = librosa.load(noisex, sr=sample_rate) mixt_num = len(data) for i in range(mixt_num): speech = data[i] x, sr = librosa.load(speech, sr=sample_rate) x, index = librosa.effects.trim(x, top_db=40, frame_length=80, hop_length=40) y, n = add_noise(x, noise, snr, tr_tst, sr) t_mid = (t_max * sample_rate) / 2 if (x.shape[0] > t_max * sample_rate): x = x[len(x) / 2 - t_mid:len(x) / 2 + t_mid] n = n[len(n) / 2 - t_mid:len(n) / 2 + t_mid] y = y[len(y) / 2 - t_mid:len(y) / 2 + t_mid] x_mag, x_phase, y_mag, y_phase, ibm, frame_numb, fbank = speech_process( x, y, n, LC, sample_rate, frameLen, n_fft, hop_length, win_length, nfilt) if (i == 0): X_mag = x_mag X_phase = x_phase Y_mag = y_mag Y_phase = y_phase IBM = ibm else: X_mag = np.concatenate((X_mag, x_mag)) X_phase = np.concatenate((X_phase, x_phase)) Y_mag = np.concatenate((Y_mag, y_mag)) Y_phase = np.concatenate((Y_phase, y_phase)) IBM = np.concatenate((IBM, ibm)) Frame_numb.append(frame_numb) print("Wykonano {} mieszanin".format(i + 1)) return IBM, Y_mag, Y_phase, X_mag, X_phase, Frame_numb, fbank
import os import sys import speech_process def usage(): print "Used to process wav in a labeled directory " print "python dir_process.py directory label" if len(sys.argv) < 4: usage() sys.exit() if os.path.isdir(sys.argv[1]) == False: print "%s is not a directory" & sys.arg[1] sys.exit() out = sys.argv[3] path = sys.argv[1] files = os.listdir(path) label = sys.argv[2] print label if path.endswith('/') == False: path = path + '/' for f in files: print f f = path + f speech_process.speech_process(f, label=label, dataFile=out)
for arg in sys.argv[2:]: if arg.startswith('-c'): channelNum = int(arg[2:]) elif arg.startswith('-r'): sampleRate = int(arg[2:]) elif arg.startswith('-w'): sampleWidth = int(arg[2:]) elif arg.startswith('-e'): littleEndian = int(arg[2:]) elif arg.startswith('-l'): logFile = str(arg[2:]) else: print "Unrecgonize parameter :%s"%arg usage() sys.exit() record = speech_process.speech_process(sys.argv[1],nchannels=channelNum,sampleRate=sampleRate,sampleWidth=sampleWidth,littleEndian=littleEndian,logFile=logFile) time = np.arange(record.frameNum) plt.subplot(511) plt.plot(time,record.volume) plt.subplot(512) plt.plot(time,record.zcr) plt.subplot(513) plt.plot(time,record.shortTimeEnergy) plt.subplot(514) plt.specgram(record.rawData,Fs=record.sampleRate,scale_by_freq = True) time2 = np.arange(len(record.pitch)) plt.subplot(515) #plt.plot(time2,record.pitch)
channelNum = int(arg[2:]) elif arg.startswith('-r'): sampleRate = int(arg[2:]) elif arg.startswith('-w'): sampleWidth = int(arg[2:]) elif arg.startswith('-e'): littleEndian = int(arg[2:]) elif arg.startswith('-l'): logFile = str(arg[2:]) else: print "Unrecgonize parameter :%s" % arg usage() sys.exit() record = speech_process.speech_process(sys.argv[1], nchannels=channelNum, sampleRate=sampleRate, sampleWidth=sampleWidth, littleEndian=littleEndian, logFile=logFile) time = np.arange(record.frameNum) plt.subplot(511) plt.plot(time, record.volume) plt.subplot(512) plt.plot(time, record.zcr) plt.subplot(513) plt.plot(time, record.shortTimeEnergy) plt.subplot(514) plt.specgram(record.rawData, Fs=record.sampleRate, scale_by_freq=True) time2 = np.arange(len(record.pitch))
def record_process(recordFile,logFile,channelNum,sampleRate,sampleWidth,littleEndian): speech_process.speech_process(recordFile,nchannels=channelNum,sampleRate=sampleRate,sampleWidth=sampleWidth,littleEndian=littleEndian,logFile=logFile)
import os import sys import speech_process def usage(): print "Used to process wav in a labeled directory " print "python dir_process.py directory label" if len(sys.argv)<4 : usage() sys.exit() if os.path.isdir(sys.argv[1])==False: print "%s is not a directory"&sys.arg[1] sys.exit() out = sys.argv[3] path = sys.argv[1] files = os.listdir(path) label = sys.argv[2] print label if path.endswith('/')==False: path = path + '/' for f in files: print f f = path + f speech_process.speech_process(f,label=label,dataFile=out)