mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 16:00:56 +01:00
Added recordings
Finished module 2
This commit is contained in:
parent
79042eeb50
commit
ce6d13645b
@ -603,40 +603,7 @@
|
|||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"source": [
|
"source": [
|
||||||
"for i, device in enumerate(sounddevice.query_devices()):\n",
|
"for i, device in enumerate(sounddevice.query_devices()):\n",
|
||||||
" print(i, device['name'])\n"
|
" print(i, device['name'])"
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"source": [
|
|
||||||
"Once you have identified the index of the microphone array device from the list, you can initialize it by specifying the device index (`device_index`) and the desired sampling frequency (`Fs`).\n",
|
|
||||||
"\n",
|
|
||||||
"Here’s how you can open the audio stream using Sounddevice:"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "code",
|
|
||||||
"outputs": [],
|
|
||||||
"execution_count": null,
|
|
||||||
"source": [
|
|
||||||
"import sounddevice as sd\n",
|
|
||||||
"\n",
|
|
||||||
"#device_index = 15 # your input device index\n",
|
|
||||||
"#Fs = 48000 # sample rate\n",
|
|
||||||
"\n",
|
|
||||||
"# 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",
|
|
||||||
"#stream.stop()"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -659,45 +626,17 @@
|
|||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"source": [
|
"source": [
|
||||||
"Fs = 48000\n",
|
"Fs = 48000\n",
|
||||||
"duration = 30\n",
|
"duration = 5\n",
|
||||||
"N = int(Fs * duration)\n",
|
"N = int(Fs * duration)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"sd.default.device = 15 # or a substring of its name\n",
|
"sounddevice.default.device = 15 # or a substring of its name\n",
|
||||||
"sd.default.samplerate = Fs\n",
|
"sounddevice.default.samplerate = Fs\n",
|
||||||
"\n",
|
"\n",
|
||||||
"samples = sd.rec(N, samplerate=Fs, channels=5)\n",
|
"samples = sounddevice.rec(N, samplerate=Fs, channels=5)\n",
|
||||||
"sd.wait()\n",
|
"sounddevice.wait()\n",
|
||||||
"print(samples.shape)"
|
"print(samples.shape)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"source": [
|
|
||||||
"At this point, the microphone data is **interleaved**. This means that the first value (`data[0]`) corresponds to the first sample of microphone 0, the second value (`data[1]`) corresponds to the first sample of microphone 1, and so on. For example, `data[5]` contains the second sample of microphone 0, and the pattern continues. To visualize the interleaving of the data, refer to the table below:\n",
|
|
||||||
"\n",
|
|
||||||
"| data[0] | data[1] | data[2] | data[3] | data[4] | data[5] | data[6] | data[7] | ... |\n",
|
|
||||||
"|---------|---------|---------|---------|---------|---------|---------|---------|-----|\n",
|
|
||||||
"| mic 0 | mic 1 | mic 2 | mic 3 | mic 4 | mic 0 | mic 1 | mic 2 | ... |\n",
|
|
||||||
"| frame 0 | frame 0 | frame 0 | frame 0 | frame 0 | frame 1 | frame 1 | frame 1 | ... |\n",
|
|
||||||
"\n",
|
|
||||||
"#### Deinterleaving the data\n",
|
|
||||||
"\n",
|
|
||||||
"To work with the data from each microphone independently, the **interleaved data** must be split into separate streams for each microphone. This process is called **deinterleaving**.\n",
|
|
||||||
"\n",
|
|
||||||
"Write a function to deinterleave the audio data and store the samples from each microphone in a separate numpy array:"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"metadata": {},
|
|
||||||
"cell_type": "code",
|
|
||||||
"outputs": [],
|
|
||||||
"execution_count": null,
|
|
||||||
"source": [
|
|
||||||
"### Student Version ###\n",
|
|
||||||
"# TODO: Reshape the data into a matrix with 5 columns (one for each microphone)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
@ -723,14 +662,14 @@
|
|||||||
"ax[2].plot(t,samples_reshaped[:,2])\n",
|
"ax[2].plot(t,samples_reshaped[:,2])\n",
|
||||||
"ax[3].plot(t,samples_reshaped[:,3])\n",
|
"ax[3].plot(t,samples_reshaped[:,3])\n",
|
||||||
"ax[4].plot(t,samples_reshaped[:,4])\n",
|
"ax[4].plot(t,samples_reshaped[:,4])\n",
|
||||||
"for ax_in in ax:\n",
|
"for i,ax_in in enumerate(ax):\n",
|
||||||
" ax_in.set_xlabel('Time (s)')\n",
|
" ax_in.set_xlabel('Time (s)')\n",
|
||||||
" ax_in.set_ylabel('Amplitude')\n",
|
" ax_in.set_ylabel('Amplitude')\n",
|
||||||
|
" ax_in.set_title(f'Mic {i}')\n",
|
||||||
"fig.show()\n",
|
"fig.show()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"from scipy.io import wavfile\n",
|
"from scipy.io import wavfile\n",
|
||||||
"wavfile.write(\"./audio_beacon_67676767_10s_driving.wav\", Fs, samples_reshaped.astype(np.float32))\n",
|
"wavfile.write(\"./audio_beacon_67676767_at_x345_y101.wav\", Fs, samples_reshaped.astype(np.float32))"
|
||||||
"# TODO: Plot the data for each microphone"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
Manual/audio_beacon_67676767_10s.wav
Normal file
BIN
Manual/audio_beacon_67676767_10s.wav
Normal file
Binary file not shown.
BIN
Manual/audio_beacon_67676767_10s_driving.wav
Normal file
BIN
Manual/audio_beacon_67676767_10s_driving.wav
Normal file
Binary file not shown.
BIN
Manual/audio_beacon_67676767_at_x180_y333.wav
Normal file
BIN
Manual/audio_beacon_67676767_at_x180_y333.wav
Normal file
Binary file not shown.
BIN
Manual/audio_beacon_67676767_at_x345_y101.wav
Normal file
BIN
Manual/audio_beacon_67676767_at_x345_y101.wav
Normal file
Binary file not shown.
BIN
Manual/clapping.wav
Normal file
BIN
Manual/clapping.wav
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user