Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Created July 10, 2019 07:37
Show Gist options
  • Save aravindpai/5f200d64efd282440d5dc58ffe26a593 to your computer and use it in GitHub Desktop.
Save aravindpai/5f200d64efd282440d5dc58ffe26a593 to your computer and use it in GitHub Desktop.
import sounddevice as sd
import soundfile as sf
samplerate = 16000
duration = 1 # seconds
filename = 'yes.wav'
print("start")
mydata = sd.rec(int(samplerate * duration), samplerate=samplerate,
channels=1, blocking=True)
print("end")
sd.wait()
sf.write(filename, mydata, samplerate)
@sahanagiri
Copy link

Sir, I am getting error in this line:
mydata = sd.rec(int(samplerate * duration), samplerate=samplerate,
channels=1, blocking=True)
PortAudioError: Error querying device -1
How to solve this. Please help me

@HabibaMersal
Copy link

i keep getting the same error @sahanagiri have you solved it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment