I've looked at all the example code but can't seem to read audio from my RME card using PyAudio. here is the code I'm using:
import wave
import scipy.io.wavfile as waveIO
from __future__ import division
import pyaudio
import time
p=pyaudio.PyAudio()
def record_audio(RECORD_SECONDS,MIC_channel):
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
stream_in = p.open(rate=RATE,
channels=CHANNELS,
format=FORMAT,
input=True,
input_device_index=MIC_channel,
frames_per_buffer=CHUNK)
frames = ""
t=time.time()
for i in range(0, int((RATE / CHUNK) * RECORD_SECONDS)):
data = stream_in.read(CHUNK)
frames=frames+data
elapsed=time.time() - t
print('I read the data in %f seconds' %elapsed)
stream_in.stop_stream()
stream_in.close()
return frames
record_audio(5,40)
I expect this code to read 5 seconds of audio. However, the audio I get is just noise so I added the timer lines to check. the answer I get is 'I read the data in 0.001 seconds'.
The length of the frames string is correct (sample_rate*2 (bytes per sample) * 5 seconds).
The number of frames is also correct. So it just looks like the data=stream_in.read(CHUNK)
line takes up almost no time while I expected it to take CHUNK/RATE.