PyAudio Input overflowed

后端 未结 9 1563
长发绾君心
长发绾君心 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条回答
  •  Happy的楠姐
    2020-11-30 04:40

    My other answer solved the problem in most cases. However sometimes the error still occurs.

    That was the reason why I scrapped pyaudio and switched to pyalsaaudio. My Raspy now smoothly records any sound.

    import alsaaudio   
    import numpy as np
    import array
    
    # constants
    CHANNELS    = 1
    INFORMAT    = alsaaudio.PCM_FORMAT_FLOAT_LE
    RATE        = 44100
    FRAMESIZE   = 1024
    
    # set up audio input
    recorder=alsaaudio.PCM(type=alsaaudio.PCM_CAPTURE)
    recorder.setchannels(CHANNELS)
    recorder.setrate(RATE)
    recorder.setformat(INFORMAT)
    recorder.setperiodsize(FRAMESIZE)
    
    
    buffer = array.array('f')
    while :
        buffer.fromstring(recorder.read()[1])
    
    data = np.array(buffer, dtype='f')
    

提交回复
热议问题