1

i'm looking for a way to stream NAO microphone/s audio to my python app. Closest i found was there: NAO robot remote audio problems. I removed the file saving and added audio stream + set only 1 channel for now:

    def start(self):
        audio = naoqi.ALProxy("ALAudioDevice", self.strNaoIp, 9559)
        nNbrChannelFlag = 3  # ALL_Channels: 0,  AL::LEFTCHANNEL: 1, AL::RIGHTCHANNEL: 2; AL::FRONTCHANNEL: 3  or AL::REARCHANNEL: 4.
        nDeinterleave = 0
        nSampleRate = 16000
        audio.setClientPreferences(self.getName(), nSampleRate, nNbrChannelFlag,
                                   nDeinterleave)  # setting same as default generate a bug !?!
        audio.subscribe(self.getName())
        print("INF: SoundReceiver: started!")

def processRemote(self, nbOfChannels, nbrOfSamplesByChannel, aTimeStamp, buffer_audio):
        """
        This is THE method that receives all the sound buffers from the "ALAudioDevice" module
        https://stackoverflow.com/questions/24243757/nao-robot-remote-audio-problems
        """
        aSoundDataInterlaced = np.fromstring(str(buffer_audio), dtype=np.int16)

        aSoundData = np.reshape(aSoundDataInterlaced, (nbOfChannels, nbrOfSamplesByChannel), 'F')
        # print "input data:", aSoundDataInterlaced
        # print "Processed data:", aSoundData

        if (True):
            # compute peak
            aPeakValue = np.max(aSoundData)
            if (aPeakValue > 16000):
                print("Peak: %s" % aPeakValue)

            p = pyaudio.PyAudio()

            def callback(in_data, frame_count, time_info, status):
                return (buffer_audio, pyaudio.paContinue)
                # return (aSoundDataInterlaced, pyaudio.paContinue)
            print nbOfChannels
            print nbrOfSamplesByChannel
            print aTimeStamp

            stream = p.open(format=p.get_format_from_width(1),
                            channels=nbOfChannels,
                            rate=nbrOfSamplesByChannel,
                            output=True,
                            stream_callback=callback)
            # stream.write(aSoundData[0])
            stream.start_stream()

However when i launch it the sound is similiar to metro coming to a station (air moving). When i try to print out value of sampling frequency (nbrOfSamplesByChannel) it prints out 1365. Isn't it supposed to be 16000 same as sampling frequency? According to softbank info it is supposed to have 170ms buffer but i don't know how to work with that or if it is relevant (http://doc.aldebaran.com/2-1/naoqi/audio/alaudiodevice.html#alaudiodevice)

Any help would be deeply appreciated.

0 Answers0