mirror of
https://gitlab.ewi.tudelft.nl/ee2l1/2025-2026/A.K.03.git
synced 2025-12-12 15:50:57 +01:00
Recording functional now.
This commit is contained in:
parent
e0f5eaa86d
commit
79042eeb50
@ -623,19 +623,20 @@
|
||||
"source": [
|
||||
"import sounddevice as sd\n",
|
||||
"\n",
|
||||
"device_index = 15 # your input device index\n",
|
||||
"Fs = 48000 # sample rate\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",
|
||||
"#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",
|
||||
"\n",
|
||||
"stream.start()\n"
|
||||
"#stream.start()\n",
|
||||
"#stream.stop()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -657,11 +658,16 @@
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"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)"
|
||||
"Fs = 48000\n",
|
||||
"duration = 30\n",
|
||||
"N = int(Fs * duration)\n",
|
||||
"\n",
|
||||
"sd.default.device = 15 # or a substring of its name\n",
|
||||
"sd.default.samplerate = Fs\n",
|
||||
"\n",
|
||||
"samples = sd.rec(N, samplerate=Fs, channels=5)\n",
|
||||
"sd.wait()\n",
|
||||
"print(samples.shape)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -708,16 +714,22 @@
|
||||
"execution_count": null,
|
||||
"source": [
|
||||
"### Student Version ###\n",
|
||||
"samples_reshaped = np.array(samples)\n",
|
||||
"fig, ax = plt.subplots(5,1,figsize=(20,30))\n",
|
||||
"\n",
|
||||
"t = np.arange(0,5,1/Fs)\n",
|
||||
"t = np.arange(0,N/Fs,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",
|
||||
"for ax_in in ax:\n",
|
||||
" ax_in.set_xlabel('Time (s)')\n",
|
||||
" ax_in.set_ylabel('Amplitude')\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"
|
||||
]
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user