Skip to content

Instantly share code, notes, and snippets.

@gerritjvv
Created January 28, 2021 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerritjvv/939a97e2562cdaa5644d5d42f709013f to your computer and use it in GitHub Desktop.
Save gerritjvv/939a97e2562cdaa5644d5d42f709013f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# pip3 install sounddevice --user
# pip3 install numpy
# pip3 install scipy
import sounddevice as sd
import numpy as np
fs=44100
duration = 5 # seconds
myrecording = sd.rec(duration * fs, samplerate=fs, channels=2,dtype='float64')
print("Recording Audio")
sd.wait()
print("Audio recording complete , Play Audio")
sd.play(myrecording, fs)
sd.wait()
print(f"Type {type(myrecording)} shape {myrecording.shape}")
print(f"value {myrecording[0]}")
with open('./myrecording', 'wb') as file:
np.save(file, myrecording)
print("Play Audio Complete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment