python pyaudio problem (Traceback (most recent call last))

62 views Asked by At
import pyaudio
import socket
import select
import sys

FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 1024

audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT, channels=2, rate=RATE, input=True, frames_per_buffer=CHUNK)
stream.start_stream()


serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('', 4444))
serversocket.listen(5)


def callback(in_data, frame_count, time_info, status):
    for s in read_list[1:]:
        s.send(in_data)
    return (None, pyaudio.paContinue)


# start Recording


read_list = [serversocket]
print ("recording...")

try:
    while True:
        readable, writable, errored = select.select(read_list, [], [])
        for s in readable:
            if s is serversocket:
                (clientsocket, address) = serversocket.accept()
                read_list.append(clientsocket)
                print ("Connection from", address)
            else:
                data = s.recv(1024)
                if not data:
                    read_list.remove(s)
except KeyboardInterrupt:
    pass


print ("finished recording")

serversocket.close()
# stop Recording
stream.stop_stream()
stream.close()
audio.terminate()

enter image description here

I'm trying to learn but I'm getting this error and I can't get it to work.I have no idea why this is the case, I've just started, I would be very happy if you could help me with the solution. I got the code from the internet, I didn't write it myself, I wanted to run it and test it.

stream = audio.open(format=FORMAT, channels=2, rate=RATE, input=True, frames_per_buffer=CHUNK)

It works when I remove this part.

0

There are 0 answers