I am using a library in Python called SoundDevice. I am trying to record a NumPy array of undefined length. Using some example code that does the same thing with a Queue object I have rewritten the callback using append from numpy. The data appears to be there in callback, but for reasons unclear to me append is not writing to the array. At the end of the test I get the original empty array.
Here is the code:
import numpy as np
import sounddevice as sd
fs = 44100
sd.default.samplerate = fs
sd.default.device = 10
x = np.array([],ndmin = 2)
def Record():
def callback(indata,frames,time,status):
if status:
print(status,flush=True)
np.append(x,indata.copy())
with sd.InputStream(fs,10,channels=1,callback = callback):
print("Recording started...")
def StopRec():
sd.stop()
print("Recording stopped.")
print(x)
Record()
for i in range(10):
pass
StopRec()