Example #1
0
def segmental_log_spectrum_distance(s, shat, winsize, winfunc):
    size = min(len(s), len(shat))
    nf = size / (winsize / 2) - 1
    ret = []
    for no in xrange(nf):
        s_i = get_frame(s, winsize, no)
        shat_i = get_frame(shat, winsize, no)
        ret.append(log_spectrum_distance(s_i, shat_i, winfunc))
    return ret
Example #2
0
def segmental_log_spectrum_distance(s, shat, winsize, winfunc):
    size = min(len(s), len(shat))
    nf = size / (winsize / 2) - 1
    ret = []
    for no in xrange(nf):
        s_i = get_frame(s, winsize, no)
        shat_i = get_frame(shat, winsize, no)
        ret.append(log_spectrum_distance(s_i, shat_i, winfunc))
    return ret
Example #3
0
 def padded_append(self, last_token, token, text_buffer):
     if last_token and last_token.span:
         spaces = token.span.start - last_token.span.stop
     elif last_token:
         spaces = 1
     else:
         spaces = 0
     for i in xrange(spaces):
         text_buffer.append(' ')
     text_buffer.append(token.norm)
 def padded_append(self, last_token, token, text_buffer):
     if last_token and last_token.span:
       spaces = token.span.start - last_token.span.stop
     elif last_token:
       spaces = 1
     else:
       spaces = 0
     for i in xrange(spaces):
       text_buffer.append(' ')
     text_buffer.append(token.norm)
def run_processor(process, args, doc_class=None, automagic=False, dealer_url='inproc://workers'):
  if any(getattr(args, a, None) for a in ('serve_url', 'worker_url')):
    context = zmq.Context(1)
    if args.serve_url:
      clients = context.socket(zmq.ROUTER)
      clients.bind(args.serve_url)
      workers = context.socket(zmq.DEALER)
      workers.bind(dealer_url)
    else:
      dealer_url = args.worker_url

    run = lambda: process(zmq_coroutine(context, dealer_url, doc_class, automagic))
    threads = [threading.Thread(target=run) for i in xrange(args.nthreads)]
    for thread in threads:
      thread.start()

    if args.serve_url:
      zmq.device(zmq.QUEUE, clients, workers)
  else:
    process(stream_coroutine(sys.stdin, sys.stdout, doc_class, automagic))
Example #6
0
        int32_ary_sound = sp.int32(ary_sound)
        int32_ary_noise = sp.int32(ary_noise)
        ary2 = sp.int16(int32_ary_sound + int32_ary_noise)
        data2 = ary2.tostring()
        synth.writeframes(data2)
        remain = remain - s
    sound.close()
    noise.close()
    synth.close()

    infile = 'tools/sound/noisy.wav'
    signal, params = read_signal(infile, WINSIZE)
    nf = len(signal) / (WINSIZE / 2) - 1
    sig_out = sp.zeros(len(signal), sp.float32)
    window = sp.hanning(WINSIZE)

    ms = MinimumStatistics(WINSIZE, window, params[2])
    NP_lambda = compute_avgpowerspectrum(signal[0:WINSIZE * int(params[2] / float(WINSIZE) / 3.0)],
                                         WINSIZE, window)
    ms.init_noise_profile(NP_lambda)
    ss = JointMap(WINSIZE, window)
    for no in xrange(nf):
        frame = get_frame(signal, WINSIZE, no)
        n_pow = ms.compute(frame, no)
        res = ss.compute_by_noise_pow(frame, n_pow)
        add_signal(sig_out, res, WINSIZE, no)

    ms.show_debug_result()
    write_signal("tools/sound/noise_reduction.wav", params, sig_out)
Example #7
0
        int32_ary_sound = sp.int32(ary_sound)
        int32_ary_noise = sp.int32(ary_noise)
        ary2 = sp.int16(int32_ary_sound + int32_ary_noise)
        data2 = ary2.tostring()
        synth.writeframes(data2)
        remain = remain - s
    sound.close()
    noise.close()
    synth.close()

    infile = 'tools/sound/noisy.wav'
    signal, params = read_signal(infile, WINSIZE)
    nf = len(signal) / (WINSIZE / 2) - 1
    sig_out = sp.zeros(len(signal), sp.float32)
    window = sp.hanning(WINSIZE)

    ms = MinimumStatistics(WINSIZE, window, params[2])
    NP_lambda = compute_avgpowerspectrum(
        signal[0:WINSIZE * int(params[2] / float(WINSIZE) / 3.0)], WINSIZE,
        window)
    ms.init_noise_profile(NP_lambda)
    ss = JointMap(WINSIZE, window)
    for no in xrange(nf):
        frame = get_frame(signal, WINSIZE, no)
        n_pow = ms.compute(frame, no)
        res = ss.compute_by_noise_pow(frame, n_pow)
        add_signal(sig_out, res, WINSIZE, no)

    ms.show_debug_result()
    write_signal("tools/sound/noise_reduction.wav", params, sig_out)