From e6e4fcc516993181117ba8601f430cb56c82ca3b Mon Sep 17 00:00:00 2001 From: Thomas Bolteau <48215561+Ery4z@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:09:47 +0100 Subject: [PATCH] Created a section Record Microphone This commit add cheat sheet to record a microphone to a wav file using sounddevice and scipy. --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 809e20c..df356ae 100644 --- a/README.md +++ b/README.md @@ -2952,7 +2952,42 @@ samples_f = it.chain.from_iterable(get_samples(n) for n in f'{P1},{P1},{P2}'.s samples_b = b''.join(struct.pack(' 1 Microphone (Yeti Classic), MME (2 in, 0 out)` + +*Exemple of an invalid device* +`< 23 PLG2773H (NVIDIA High Definitio, MME (0 in, 2 out)` + +**Record the microphone and save it to wav file** +```python +recording_length = 5 # seconds +fs = 44100 # Sample rate +device_index_to_record = 1 # Number before the name of the peripheral displayed at the step before + +stream = sounddevice.InputStream(samplerate=fs,device=device_index_to_record,dtype="float32") # Initialise the stream +stream.start() # Start the stream + +record = stream.read(int(recording_length * fs)) # Record the stream +# This return a tuple with the actual record and the sample frequency + +wavfile.write("my_microphone.wav", fs, record[0]) # Write to the file + +``` Pygame ------