Skip to content

Instantly share code, notes, and snippets.

@oplatek
Created December 28, 2016 22:31
Show Gist options
  • Save oplatek/8ebd47bcac7bae41d59262010cc3ea80 to your computer and use it in GitHub Desktop.
Save oplatek/8ebd47bcac7bae41d59262010cc3ea80 to your computer and use it in GitHub Desktop.
Record 16bit 16khz pcm from python
# coding: utf-8
import sounddevice as sd
duration = 10
fs = 16000
rec = sd.rec(duration * fs, samplerate=fs, channels=1, dtype='int16')
sd.wait()
pcm = rec.tostring()
with open('test.raw', 'wb') as w:
w.write(pcm)
# Use following sox command to play it
# play -r 16000 -e signed-integer -b 16 test.raw
@JRY-Zheng
Copy link

Wonderful!!!!

@vflonbeulin
Copy link

Thanks !

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