|
|
@ -2978,7 +2978,42 @@ def play_notes(notes, bpm=132, f=44100): |
|
|
|
play_notes('83♩,81♪,,83♪,,78♪,,74♪,,78♪,,71♪,,,,83♪,,81♪,,83♪,,78♪,,74♪,,78♪,,71♪,,,,' |
|
|
|
'83♩,85♪,,86♪,,85♪,,86♪,,83♪,,85♩,83♪,,85♪,,81♪,,83♪,,81♪,,83♪,,79♪,,83♪,,,,') |
|
|
|
``` |
|
|
|
Record Microphone |
|
|
|
----------------- |
|
|
|
```python |
|
|
|
# $ pip install souddevice |
|
|
|
# $ pip install scipy |
|
|
|
|
|
|
|
import sounddevice |
|
|
|
from scipy.io import wavfile |
|
|
|
``` |
|
|
|
**List available audio device** |
|
|
|
```python |
|
|
|
available_devices = sounddevice.query_devices() |
|
|
|
``` |
|
|
|
*Exemple of a valid device. It is necessary to have a non nul number of in channel.* |
|
|
|
|
|
|
|
`> 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 |
|
|
|
------ |
|
|
|