Created
December 28, 2016 22:31
-
-
Save oplatek/8ebd47bcac7bae41d59262010cc3ea80 to your computer and use it in GitHub Desktop.
Record 16bit 16khz pcm from python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wonderful!!!!