Ejemplo n.º 1
0
def callback(msg):

    global record
    global data
    global count

    data = append(data, msg.data)
    #print len(msg.data)
    count += 1

    if count == N_CYCLES:
        signal_1 = data[::2]
        signal_2 = data[1::2]
        #signal_1 = [struct.unpack('B', struct.pack('b',d))[0] for d in data[::2]]
        #signal_2 = [struct.unpack('B', struct.pack('b',d))[0] for d in data[1::2]]

        print len(signal_1)
        print signal_1
        print "number of samples(frames): " + str(len(signal_1))
        print "SAMPLING RATE: " + str(RATE) + "(Hz)"
        print "DURATION: " + str(DURATION) + "(s)"

        helper.plot_from_rawdata(signal_1, signal_2, RATE)

        rospy.signal_shutdown("Recording finished")
Ejemplo n.º 2
0
def callback(msg):

    global record
    global data
    global count

    data = append(data, msg.data)
    # print len(msg.data)
    count += 1

    if count == N_CYCLES:
        signal_1 = data[::2]
        signal_2 = data[1::2]
        # signal_1 = [struct.unpack('B', struct.pack('b',d))[0] for d in data[::2]]
        # signal_2 = [struct.unpack('B', struct.pack('b',d))[0] for d in data[1::2]]

        print len(signal_1)
        print signal_1
        print "number of samples(frames): " + str(len(signal_1))
        print "SAMPLING RATE: " + str(RATE) + "(Hz)"
        print "DURATION: " + str(DURATION) + "(s)"

        helper.plot_from_rawdata(signal_1, signal_2, RATE)

        rospy.signal_shutdown("Recording finished")
Ejemplo n.º 3
0
    ####################################################
    ######## Getting Sound Data through PyAudio ########
    ####################################################
    n_reads = int(RATE * RECORD_SECONDS / CHUNK)
    print 'n_reads=', n_reads
    data = ''.join([stream.read(CHUNK) for i in range(n_reads)])
    print 'len(data)=', len(data)
    if FORMAT == pyaudio.paInt16:
        signal = struct.unpack("<%uh" % (len(data) / 2), data)
    elif FORMAT == pyaudio.paInt24:
        signal = [struct.unpack('<i', data[i:i+3] + 
                  ('\0' if data[i+2] < '\x80' else '\xff'))[0] 
                  for i in range(0, len(data), 3)]
    elif FORMAT == pyaudio.paInt32:
        signal = struct.unpack("<%ul" % (len(data) / 4), data)
    else:
        raise TypeError("Not supported PyAudio format")
    if args.save_file:
        pickle.dump(signal, args.save_file)
    print("* done recording")
    stream.stop_stream()
    stream.close()
    p.terminate()

N = args.N if args.N else 2048
Ns = args.Ns if args.Ns else 1024
overlap_ratio = args.overlap_ratio if args.overlap_ratio else 0.7
signal = signal[:N]
helper.plot_from_rawdata(signal[0::2], signal[1::2], RATE, Ns, overlap_ratio)