PyAudio memory error

I am having a problem with my code that is causing a memory error. I believe this is caused by this function (see below).

def sendAudio ():
    p = pyaudio.PyAudio ()
    stream = p.open (format = FORMAT,
                    channels = CHANNELS,
                    rate = RATE,
                    input = True,
                    output = True,
                    frames_per_buffer = chunk)

    data = stream.read (chunk)
    client (chr (CMD_AUDIO), encrypt_my_audio_message (data))

def keypress (event):
    if event.keysym == 'Escape':
        root.destroy ()
    if event.keysym == 'Control_L':
        #print ("Sending Data ...")
        sendAudio ()
        #print ("Data Sent!")

, , . , - , ( ..). , , , , , .

Thnak

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 552, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "chat.py", line 62, in server
    frames_per_buffer = chunk)
  File "C:\Python27\lib\site-packages\pyaudio.py", line 714, in open
    stream = Stream(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\pyaudio.py", line 396, in __init__
    self._stream = pa.open(**arguments)
IOError: [Errno Insufficient memory] -9992
+2
1

? PortAudio, . , , , :

try:
    data = stream.read(chunk)
except IOError as ex:
    if ex[1] != pyaudio.paInputOverflowed:
        raise
    data = '\x00' * chunk  # or however you choose to handle it, e.g. return None
+2

Source: https://habr.com/ru/post/1014507/


All Articles