if len(args) != 1: parser.print_help() exit(2) fname = args[0] signal, params = read(fname, options.winsize) window = sp.hanning(options.winsize) import os.path root, ext = os.path.splitext(args[0]) if options.method == 0: ss = SpectralSubtruction(options.winsize, window, ratio=options.ratio, coefficient=options.sscoefficient) outfname = "%s_ss%s" % (root, ext) elif options.method == 1: ss = MMSE_STSA(options.winsize, window, ratio=options.ratio, constant=options.constant, alpha=options.alpha) outfname = "%s_mmse%s" % (root, ext) elif options.method == 2: ss = MMSE_LogSTSA(options.winsize, window, ratio=options.ratio, alpha=options.alpha, constant=options.constant) outfname = "%s_lmmse%s" % (root, ext) elif options.method == 3: ss = JointMap(options.winsize, window, alpha=options.alpha, ratio=options.ratio, constant=options.constant) outfname = "%s_jm%s" % (root, ext) if params[0] == 1: write(params, noise_reduction(signal, params, options. winsize, window, ss, options.ntime)) elif params[0] == 2: l, r = separate_channels(signal) write(params, uniting_channles(noise_reduction(l, params, options.winsize, window, ss, options.ntime), noise_reduction(r, params, options.winsize, window, ss, options.ntime)))
import os.path root, ext = os.path.splitext(args[0]) if options.method == 0: ss = SpectralSubtruction(options.winsize, window) outfname = "%s_ss%s" % (root, ext) elif options.method == 1: ss = MMSE_STSA(options.winsize, window) outfname = "%s_mmse%s" % (root, ext) elif options.method == 2: ss = MMSE_LogSTSA(options.winsize, window, alpha=0.99) outfname = "%s_lmmse%s" % (root, ext) elif options.method == 3: ss = JointMap(options.winsize, window, alpha=0.99) outfname = "%s_jm%s" % (root, ext) if params[0] == 1: write( params, noise_reduction(signal, params, options.winsize, window, ss, options.ntime)) elif params[0] == 2: l, r = separate_channels(signal) write( params, uniting_channles( noise_reduction(l, params, options.winsize, window, ss, options.ntime), noise_reduction(r, params, options.winsize, window, ss, options.ntime)))
if __name__ == "__main__": parser = optparse.OptionParser(usage="%prog [-m METHOD] [-w WINSIZE] SONGFILE KARAOKEFILE\n method 0 : SpectralSubtruction\n 1 : MMSE_STSA\n 2 : MMSE_LogSTSA\n 3 : JointMap\n if INPUTFILE is \"-\", read wave data from stdin") parser.add_option("-w", type="int", dest="winsize", default=1024) parser.add_option("-m", type="int", dest="method", default=0) (options, args) = parser.parse_args() if len(args)!=2: parser.print_help() exit(2) kl = KaraokeFileLoader(options.winsize*2) ssignal,ksignal,params = kl.load_file(args[0],args[1]) ssignal_l,ssignal_r = separate_channels(ssignal) ksignal_l,ksignal_r = separate_channels(ksignal) window = sp.hanning(options.winsize) if options.method==0: method = SpectralSubtruction(options.winsize,window) elif options.method==1: method = MMSE_STSA(options.winsize,window) elif options.method==2: method = MMSE_LogSTSA(options.winsize,window,alpha=0.99) elif options.method==3: method = JointMap(options.winsize,window,alpha=0.99) sig_out_l = subtruction(ssignal_l,ksignal_l,window,options.winsize,method) sig_out_r = subtruction(ssignal_r,ksignal_r,window,options.winsize,method)