Ejemplo n.º 1
0
def callback(data):
    
    global first
    global write_wave
    global wav_file
    global audio
    global pub
    
    if data.ok == True:
        audio.extend(data.audio_buf)
    else:
	start = time.time()
        byte_count = (len(audio)) * 4  # 32-bit floats
        wav_file = ""
        # write the header
        wav_file += struct.pack('<ccccIccccccccIHHIIHH',
                                'R', 'I', 'F', 'F',
                                byte_count + 0x2c - 8,  # header size
                                'W', 'A', 'V', 'E', 'f', 'm', 't', ' ',
                                0x10,  # size of 'fmt ' header
                                3,  # format 3 = floating-point PCM
                                1,  # channels
                                16000,  # samples / second
                                16000 * 4,  # bytes / second
                                4,  # block alignment
                                32)  # bits / sample
        wav_file += struct.pack('<ccccI',
                                'd', 'a', 't', 'a', byte_count)
        for sample in audio:
            wav_file += struct.pack("<f", sample)
        
        fi = open("/home/yhirai/openSMILE-2.1.0_other/input/bb.wav",'wb')
        for value in wav_file:
            fi.write(value)
        first = 0
        wav_file = ""
        audio = []

        msg = AudioData()
        msg.ok = True
        msg.tracking_ID = data.tracking_ID
        pub.publish(msg)
	elapsed_time = time.time() - start
	print elapsed_time        
Ejemplo n.º 2
0
def callback(data):
    
    global first
    global write_wave
    global wav_file
    global audio
    global pub

    if data.ok == True:
  
        cmd = "ffmpeg -y -i /home/yhirai/openSMILE-2.1.0_other/input/bb.wav -ab 2 -vol 256 /home/yhirai/openSMILE-2.1.0_other/input/input.wav"
        subprocess.call(cmd,shell=True)
        
        cmd3 = "rm /home/yhirai/openSMILE-2.1.0_other/input/input.arff"
        subprocess.call(cmd3,shell=True)

        cmd2 = "/home/yhirai/openSMILE-2.1.0_other/bin/linux_x64_standalone_static/SMILExtract -C /home/yhirai/openSMILE-2.1.0_other/config/IS10_paraling.conf -I /home/yhirai/openSMILE-2.1.0_other/input/input.wav -O /home/yhirai/openSMILE-2.1.0_other/input/input.arff"
        subprocess.call(cmd2,shell=True)
        
        output = 0
        time.sleep(0.1)
        #f = open("/home/yhirai/openSMILE-2.1.0_other/input/new_input.arff",'w')
        for line2 in open("/home/yhirai/openSMILE-2.1.0_other/input/input.arff",'r'):
            line2 = line2.rstrip()
            if line2 == "@attribute":
                output = 0
            if output == 1:
                str_f = line2
                #f.write(line2)
            if line2 == "@data":
                output = 1
        out_l = range(1582)
        line2 = str_f.rstrip()
        List2 = line2.split(",")
        var2 = 1
        for var in range(0,1582):
            out_l[var] = float(List2[var2])
            var2 += 1
        msg = AudioData()
        msg.ok = True
        msg.tracking_ID = data.tracking_ID
        msg.audio_buf = out_l
        pub.publish(msg)
Ejemplo n.º 3
0
def callback(data):
    
    global first
    global write_wave
    global wav_file
    global audio
    global pub
    global start
    global roop
    global all_save

    if data.ok == True:
        if first == 0:
            byte_count = (len(audio)) * 4  # 32-bit floats
            wav_file = ""
            # write the header
            wav_file += struct.pack('<ccccIccccccccIHHIIHH',
                                    'R', 'I', 'F', 'F',
                                    byte_count + 0x2c - 8,  # header size
                                    'W', 'A', 'V', 'E', 'f', 'm', 't', ' ',
                                    0x10,  # size of 'fmt ' header
                                    3,  # format 3 = floating-point PCM
                                    1,  # channels
                                    16000,  # samples / second
                                    16000 * 4,  # bytes / second
                                    4,  # block alignment
                                    32)  # bits / sample
            wav_file += struct.pack('<ccccI',
                                    'd', 'a', 't', 'a', byte_count)
            first = 1
	    if roop == 0:
		#time.sleep(0.5)
	        all_save = ""
                all_save += struct.pack('<ccccIccccccccIHHIIHH',
                                    'R', 'I', 'F', 'F',
                                    byte_count + 0x2c - 8,  # header size
                                    'W', 'A', 'V', 'E', 'f', 'm', 't', ' ',
                                    0x10,  # size of 'fmt ' header
                                    3,  # format 3 = floating-point PCM
                                    1,  # channels
                                    16000,  # samples / second
                                    16000 * 4,  # bytes / second
                                    4,  # block alignment
                                    32)  # bits / sample
                all_save += struct.pack('<ccccI',
                                        'd', 'a', 't', 'a', byte_count)
            start = time.time()
        if roop != 0:
            for sample in data.audio_buf:
                wav_file += struct.pack("<f", sample)
                all_save += struct.pack("<f", sample)
        roop = 1

	
    elif data.ok == False:
        #for sample in audio:
        #    wav_file += struct.pack("<f", sample)
        elapsed_time = time.time() - start
        #if elapsed_time < 0.5:
        #    time.sleep(0.5)
        fi = open("/home/yhirai/openSMILE-2.1.0_other/input/bb.wav",'wb')
        for value in wav_file:
            fi.write(value)
	fi2 = open("/home/yhirai/openSMILE-2.1.0_other/input/alldaze.wav",'wb')
        for value in all_save:
            fi2.write(value)	
        first = 0
	roop = 0
        wav_file = ""
        audio = []

        msg = AudioData()
        msg.ok = True
        msg.tracking_ID = data.tracking_ID
        #pub.publish(msg)
    
    if first == 1:
        elapsed_time = time.time() - start
        if elapsed_time > 2:
            fi = open("/home/yhirai/openSMILE-2.1.0_other/input/bb.wav",'wb')
            for value in wav_file:
                fi.write(value)
            first = 0
            wav_file = ""
            audio = []
            
            msg = AudioData()
            msg.ok = True
            msg.tracking_ID = data.tracking_ID
            pub.publish(msg)
            print elapsed_time