Seeking assistance to save audio as a numpy array

Hello folks, I’m trying to recordaudio input stream and export that data to the .wav file.
To achieve such result I am using soundevice library as well as scipy.io.wavfile module.
I am having difficulty understanding how to accomplish this; if you could provide me with any advice, I would be very grateful.

def record(sample_rate: int, device_id: int):
	input_latency = get_input_latency(device_id)
	frame_size = 1024
	audio_data = np.array(dtype ='int16')

	audio_input_stream = sd.InputStream(samplerate = sample_rate, channels = 1,
		dtype = np.int16, device = device_id, latency = input_latency)
	
	audio_input_stream.start()
	while keyboardHandler.get_status() != "submit":
		np.append(audio_data, audio_input_stream.read(frames = frame_size))

	Play.stop()
	audio_input_stream.stop()
	audio_input_stream.close()

	return audio_data

it’s very likely that my function above is totally wrong and I’m missing some things, however the error when trying to record is:

array() missing required argument 'object' (pos 0)

My thoughts on it are that the audio stream data itself is not correct, so therefore I can’t append that data to the “audio_data” array.
keyboard listener is a module that I made to control the whole recording situation using keyboard.

Any who, help would be really appreciated, Ineed this for my project.

I’ve only glanced over this code; there may well be structural problems here, but I can speak to the NumPy usage.

np.array is a factory function that constructs an np.ndarray, it takes at least one argument: the data. In your case, you’re only passing in the data type (dtype). To directly fix your code, you’d write

audio_data = np.empty((0, 1), dtype=np.int16)

where (0, 1) is the shape of (frames, channels) to start with.

However, this is very inefficient; every call to np.append allocates a new array, that grows with each iteration. You’re better off appending each read to a list, and finally concatenating the results if you need a single array, e.g.

frames = []
while ...:
    frames.append(audio_input_stream.read(...))

data = np.concatenate(frames, axis=0)

You say that there’s an error, but not which line it occurred on.

Please post the complete traceback wrapped in backticks:

```
(traceback lines)
```