From 2aaec1ba5c80d1005c6c82a3296c00683159113c Mon Sep 17 00:00:00 2001 From: nl <3210346136@qq.com> Date: Tue, 23 Oct 2018 10:40:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AApython?= =?UTF-8?q?=E5=BD=95=E9=9F=B3=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- speech-recorder.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 speech-recorder.py diff --git a/speech-recorder.py b/speech-recorder.py new file mode 100644 index 0000000..c4aed9e --- /dev/null +++ b/speech-recorder.py @@ -0,0 +1,49 @@ +import wave +from pyaudio import PyAudio,paInt16 + +framerate=16000 +NUM_SAMPLES=2000 +channels=1 +sampwidth=2 +TIME=10 +def save_wave_file(filename,data): + '''save the date to the wavfile''' + wf=wave.open(filename,'wb') + wf.setnchannels(channels) + wf.setsampwidth(sampwidth) + wf.setframerate(framerate) + wf.writeframes(b"".join(data)) + wf.close() + +def my_record(): + pa=PyAudio() + stream=pa.open(format = paInt16,channels=1, + rate=framerate,input=True, + frames_per_buffer=NUM_SAMPLES) + my_buf=[] + count=0 + while count