spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
980 stars 145 forks source link

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

Open snufas opened 1 year ago

snufas commented 1 year ago

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

mgeier commented 1 year ago

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 commented 1 year ago

@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.

snufas commented 1 year ago

@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

mgeier commented 1 year ago

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.