def init_params_by_noise(self, fs, noise_signal): noise_signal = self._mononize_signal(noise_signal) self.noise_signal = np.array(noise_signal) self._init_window(fs) ltsd = LTSD(self.window_size, self.window, self.order) res, ltsds = ltsd.compute_with_noise(noise_signal, noise_signal) max_ltsd = max(ltsds) self.lambda0 = max_ltsd * 1.1 self.lambda1 = self.lambda0 * 2.0
def init_params_by_noise(self, fs, noise_signal): noise_signal = self._mononize_signal(noise_signal) self.noise_signal = np.array(noise_signal) self._init_window(fs) ltsd = LTSD(self.window_size, self.window, self.order) res, ltsds = ltsd.compute_with_noise(noise_signal, noise_signal) max_ltsd = max(ltsds) self.lambda0 = max_ltsd * 1.1 self.lambda1 = self.lambda0 * 2.0 print 'max_ltsd =', max_ltsd print 'lambda0 =', self.lambda0 print 'lambda1 =', self.lambda1
def _get_ltsd(self, fs=None): if fs is not None and fs != self.fs: self._init_window(fs) return LTSD(self.window_size, self.window, self.order, lambda0=self.lambda0, lambda1=self.lambda1)
usage = "%python vad [-t THREASHOLD] [-w WINSIZE] [- s NOISETIME(ms)] "\ "INPUTFILE \n if INPUTFILE is \"-\", read wave data from stdin" parser = optparse.OptionParser(usage=usage) parser.add_option("-w", type="int", dest="winsize", default=WINSIZE) parser.add_option("-t", type="int", dest="th", default=10) parser.add_option("-s", type="int", dest="ntime", default=300) (options, args) = parser.parse_args() windowsize = options.winsize fname = args[0] signal, params = read(fname, options.winsize) window = np.hanning(windowsize) ntime = options.ntime if params[0] == 1: ltsd = LTSD(windowsize, window, 5, lambda0=options.th) res, ltsds = ltsd.compute_with_noise(signal, signal[0:windowsize*int(params[2]/float(windowsize)/(1000.0/ntime))]) write(params, vad(res, signal, windowsize, window)) elif params[0] == 2: noise_sec = windowsize*int(params[2]/float(windowsize)/(1000.0/ntime)) l, r = separate_channels(signal) ltsd_l = LTSD(windowsize, window, 5, lambda0=options.th) ltsd_r = LTSD(windowsize, window, 5, lambda0=options.th) l_out = vad(ltsd_l.compute_without_noise(l, noise_sec)[0], l, windowsize, window) r_out = vad(ltsd_r.compute_without_noise(r, noise_sec)[0], r, windowsize, window) out = uniting_channles(l_out, r_out) write(params, out)
) parser.add_option("-w", type="int", dest="winsize", default=WINSIZE) parser.add_option("-t", type="int", dest="th", default=15) parser.add_option("-s", type="int", dest="ntime", default=300) (options, args) = parser.parse_args() windowsize = options.winsize fname = args[0] signal, params = read(fname, options.winsize) window = sp.hanning(windowsize) ntime = options.ntime if params[0] == 1: ltsd = LTSD(windowsize, window, 5, lambda0=options.th) res, ltsds = ltsd.compute_with_noise( signal, signal[0:windowsize * int(params[2] / float(windowsize) / (1000.0 / ntime))]) #maybe 300ms write(params, vad(res, signal, windowsize, window)) elif params[0] == 2: l, r = separate_channels(signal) ltsd_l = LTSD(windowsize, window, 5, lambda0=options.th) ltsd_r = LTSD(windowsize, window, 5, lambda0=options.th) out = uniting_channles( vad( ltsd_l.compute_with_noise( l, l[0:windowsize * int(params[2] / float(windowsize) / (1000.0 / ntime))])[0], l, windowsize, window), vad(
if __name__ == "__main__": """ python vad.py -w WINSIZE -t THREATHOLD FILENAME """ parser = optparse.OptionParser( usage= "%python vad INPUTFILE \n if INPUTFILE is \"-\", read wave data from stdin" ) parser.add_option("-t", type="int", dest="th", default=10) (options, args) = parser.parse_args() windowsize = 1024 fname = args[0] signal, params = read(fname, windowsize) window = sp.hanning(windowsize) mhmm, nhmm = get_model("hmm.model", "noisyhmm.model") if params[0] == 1: ltsd = LTSD(windowsize, window, 6, lambda0=options.th) res, ltsds = ltsd.compute_with_noise( signal, signal[0:windowsize * int(params[2] / float(windowsize) / 3.0)]) #maybe 300ms print res res = hmm_filter(mhmm, nhmm, signal, res, windowsize, window) print res #write(params,vad(res,signal,windowsize,window)) elif params[0] == 2: write(params, signal)