mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 15:30:57 +01:00
Recording somewhat functional now.
This commit is contained in:
parent
71bca8d47f
commit
e0f5eaa86d
@ -602,10 +602,8 @@
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"sounddevice_handle = sounddevice()\n",
|
||||
"for i in range(sounddevice_handle.get_device_count()):\n",
|
||||
" device_info = sounddevice_handle.get_device_info_by_index(i)\n",
|
||||
" print(i, device_info['name'])\n"
|
||||
"for i, device in enumerate(sounddevice.query_devices()):\n",
|
||||
" print(i, device['name'])\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -623,19 +621,21 @@
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"# Initialize sounddevice again\n",
|
||||
"sounddevice_handle = sounddevice()\n",
|
||||
"import sounddevice as sd\n",
|
||||
"\n",
|
||||
"# Specify the device index and sampling frequency\n",
|
||||
"device_index = 1 # Replace with the index of your microphone device\n",
|
||||
"Fs = 44100 # or 48000, depending on the field setup. Try to use 48000 when making your own recordings.\n",
|
||||
"device_index = 15 # your input device index\n",
|
||||
"Fs = 48000 # sample rate\n",
|
||||
"\n",
|
||||
"# Open the audio stream with 5 channels, 16-bit audio format (paInt16), and the specified sample rate\n",
|
||||
"stream = sounddevice_handle.open(input_device_index=device_index,\n",
|
||||
" channels=5,\n",
|
||||
" format='float32',\n",
|
||||
" rate=Fs,\n",
|
||||
" input=True)"
|
||||
"# Open 5‑channel float32 input stream on that device\n",
|
||||
"stream = sd.InputStream(\n",
|
||||
" device=device_index, # or device=(device_index, None) for in/out\n",
|
||||
" channels=5,\n",
|
||||
" samplerate=Fs,\n",
|
||||
" dtype='float32', # 16‑bit would be 'int16'\n",
|
||||
" # or True, depending on how you use it\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"stream.start()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -657,9 +657,11 @@
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"Fs = 44100 # Sampling frequency\n",
|
||||
"N = 2*Fs # 2 seconds of audio data\n",
|
||||
"samples,_ = stream.read(N)"
|
||||
"Fs = 48000 # Sampling frequency\n",
|
||||
"N = 5*Fs # 2 seconds of audio data\n",
|
||||
"samples,_ = stream.read(N)\n",
|
||||
"samples_reshaped = np.array(samples)\n",
|
||||
"print(samples_reshaped.shape)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -687,7 +689,6 @@
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"\n",
|
||||
"# TODO: Reshape the data into a matrix with 5 columns (one for each microphone)"
|
||||
]
|
||||
},
|
||||
@ -707,6 +708,15 @@
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"fig, ax = plt.subplots(5,1,figsize=(20,30))\n",
|
||||
"\n",
|
||||
"t = np.arange(0,5,1/Fs)\n",
|
||||
"ax[0].plot(t,samples_reshaped[:,0])\n",
|
||||
"ax[1].plot(t,samples_reshaped[:,1])\n",
|
||||
"ax[2].plot(t,samples_reshaped[:,2])\n",
|
||||
"ax[3].plot(t,samples_reshaped[:,3])\n",
|
||||
"ax[4].plot(t,samples_reshaped[:,4])\n",
|
||||
"fig.show()\n",
|
||||
"\n",
|
||||
"# TODO: Plot the data for each microphone"
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user