录制百度语音识别可用的语音

import wave
from pyaudio import PyAudio,paInt16

framerate=16000
NUM_SAMPLES=2000
channels=1
sampwidth=2
TIME=2
filename='out.wav'
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(filename):
    pa=PyAudio()
    stream=pa.open(format = paInt16,channels=1,
                   rate=framerate,input=True,
                   frames_per_buffer=NUM_SAMPLES)
    my_buf=[]
    count=0
    while count         string_audio_data = stream.read(NUM_SAMPLES)
        my_buf.append(string_audio_data)
        count+=1
        print('.')
    save_wave_file(filename,my_buf)
    stream.close()

你可能感兴趣的:(研电赛)