Added recordings

Finished module 2
This commit is contained in:
Nicholas Stănescu 2025-11-28 12:16:52 +01:00
parent 79042eeb50
commit ce6d13645b
6 changed files with 9 additions and 70 deletions

View File

@ -603,40 +603,7 @@
"execution_count": null,
"source": [
"for i, device in enumerate(sounddevice.query_devices()):\n",
" print(i, device['name'])\n"
]
},
{
"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",
"Heres 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 5channel 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', # 16bit would be 'int16'\n",
" # or True, depending on how you use it\n",
"#)\n",
"\n",
"#stream.start()\n",
"#stream.stop()"
" print(i, device['name'])"
]
},
{
@ -659,45 +626,17 @@
"execution_count": null,
"source": [
"Fs = 48000\n",
"duration = 30\n",
"duration = 5\n",
"N = int(Fs * duration)\n",
"\n",
"sd.default.device = 15 # or a substring of its name\n",
"sd.default.samplerate = Fs\n",
"sounddevice.default.device = 15 # or a substring of its name\n",
"sounddevice.default.samplerate = Fs\n",
"\n",
"samples = sd.rec(N, samplerate=Fs, channels=5)\n",
"sd.wait()\n",
"samples = sounddevice.rec(N, samplerate=Fs, channels=5)\n",
"sounddevice.wait()\n",
"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": {},
"cell_type": "markdown",
@ -723,14 +662,14 @@
"ax[2].plot(t,samples_reshaped[:,2])\n",
"ax[3].plot(t,samples_reshaped[:,3])\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_ylabel('Amplitude')\n",
" ax_in.set_title(f'Mic {i}')\n",
"fig.show()\n",
"\n",
"from scipy.io import wavfile\n",
"wavfile.write(\"./audio_beacon_67676767_10s_driving.wav\", Fs, samples_reshaped.astype(np.float32))\n",
"# TODO: Plot the data for each microphone"
"wavfile.write(\"./audio_beacon_67676767_at_x345_y101.wav\", Fs, samples_reshaped.astype(np.float32))"
]
},
{

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Manual/clapping.wav Normal file

Binary file not shown.