PyAudio Input overflowed

后端 未结 9 1593
长发绾君心
长发绾君心 2020-11-30 04:04

I\'m trying to make real-time plotting sound in python. I need to get chunks from my microphone.

Using PyAudio, try to use

import pyaudio
import wav         


        
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 04:19

    pyaudio.Stream.read() has a keyword parameter exception_on_overflow, set this to False.

    For your sample code that would look like:

    import pyaudio
    import wave
    import sys
    
    chunk = 1024
    FORMAT = pyaudio.paInt16
    CHANNELS = 1
    RATE = 44100
    RECORD_SECONDS = 5
    WAVE_OUTPUT_FILENAME = "output.wav"
    
    p = pyaudio.PyAudio()
    
    stream = p.open(format = FORMAT,
                    channels = CHANNELS,
                    rate = RATE,
                    input = True,
                    frames_per_buffer = chunk)
    
    print "* recording"
    all = []
    for i in range(0, RATE / chunk * RECORD_SECONDS):
        data = stream.read(chunk, exception_on_overflow = False)
        all.append(data)
    print "* done recording"
    
    stream.close()
    p.terminate()
    

    See the PyAudio documentation for more details.

提交回复
热议问题