python-sounddevice icon indicating copy to clipboard operation
python-sounddevice copied to clipboard

Trying to record input stream... Extremely important to get help on this...

Open snufas opened this issue 3 years ago • 4 comments

Basically, I'm trying to record the input stream and export that to 1 of. My code below, I would really appreciate your input, hence I have no idea for a while now how to get this working.

def record(sample_rate: int, device_id: int):
	input_latency = get_input_latency(device_id)
	frame_size = 1024
	audio_data = np.empty(0, 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":
		data = np.asarray(audio_input_stream.read(frame_size), dtype = "int16")
		np.append(data, audio_data)
	
	Play.stop()
	audio_input_stream.stop()
	audio_input_stream.close()

	return audio_data

When trying to run this function I am geting error like so:

error: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

I got pyaudio working, but this library is better. Keep in mind that I am a newbie, so the code above might be something totally incorrect. I would appreciate help from anyone who can help me out. I know it's not supposed to be a helping form or anything like that, but I didn't get any answers in other places...

Thanks

snufas avatar Jan 29 '23 19:01 snufas

Calling this "extremely important" will not get you any faster answers (at least not from me). But maybe that's fine, since "important" doesn't necessarily mean "urgent".

https://python-sounddevice.readthedocs.io/en/0.4.5/CONTRIBUTING.html#reporting-problems

mgeier avatar Jan 31 '23 21:01 mgeier

@snufas If you provide code that I can actually run, I can try to reproduce the problem and I might be able to find out what's going wrong.

mgeier avatar Feb 18 '23 16:02 mgeier

@mgeier Yes, i would appreciate the help.

to control the recorder start = 'ctrl+shift+space' submit = 'ctrl+shift+backspace' exit = 'ctrl+shift+X' some code is commeted out because is not needet to test the actuall recording feeture.

Thanks for help. rec.zip

snufas avatar Feb 18 '23 19:02 snufas

The simpleaudio module seems to be not used.

What about the keyboard module? Is this needed to reproduce the problem.

You should remove all code that's not needed to reproduce the problem.

mgeier avatar May 21 '23 15:05 mgeier