Browse Source

Merge e6e4fcc516 into 6a70b6a899

pull/135/merge
Thomas Bolteau 1 week ago
committed by GitHub
parent
commit
593e3e141a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 35 additions and 0 deletions
  1. 35
      README.md

35
README.md

@ -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
------

Loading…
Cancel
Save