Python Forum
Can PyAudio (Port Audio) validly accept float values when writing to stream? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Can PyAudio (Port Audio) validly accept float values when writing to stream? (/thread-2560.html)



Can PyAudio (Port Audio) validly accept float values when writing to stream? - cdrandin - Mar-24-2017

I am trying to send over audio data from an iOS device and send it to another device which is using PyAudio to play the sound.

I have been able to successfully do this from python device to python device, but now I am trying to get iOS device to python device.

The issue I am having at the moment is when capturing audio data on iOS I get an array of float values. When I transfer the data and play it with PyAudio I just get a bunch of feedback. 

Now I am wondering can PyAudio handle float values at all? How could I properly handle float data for audio that PyAudio can play it properly or do I need to change the format.

How I am currently getting the audio:

[Objective-C]
Novocaine *audioManager = [Novocaine audioManager];
[audioManager setInputBlock:^(float *newAudio, UInt32 numSamples, UInt32 numChannels) {
// Now you're getting audio from the microphone every 20 milliseconds or so. How's that for easy?
// Audio comes in interleaved, so,
// if numChannels = 2, newAudio[0] is channel 1, newAudio[1] is channel 2, newAudio[2] is channel 1, etc.
}];
[audioManager play];
[/Objective-C]

How I am trying to play the audio:

def audioStream_ios(payload):
            if stream.is_active():
                # print payload
                self.buffer += payload
                stream.write(payload)
        yield self.subscribe(audioStream_ios, 'com.app.audioStream_ios')

        while 1:
            if stream.is_active() and len(self.buffer) >= CHUNK * 1:
                data = self.buffer[:CHUNK]
                self.buffer = self.buffer[CHUNK:]
                print 'write'
                stream.write(data)

            yield sleep(0.01)



RE: Can PyAudio (Port Audio) validly accept float values when writing to stream? - nilamo - Mar-26-2017

Could it be because you're writing the same data to the stream twice? Once just after adding it to the buffer, and then again when you shift it off the buffer.