Я пытаюсь закодировать голосовой чат, используя socket и pyaudio в python. Я написал его, и он работает, но он вызывает ошибки, которые
ALSA lib pcm_dmix.c: 1052: (snd_pcm_dmix_open) не могут открыть ведомое устройство
ALSA lib pcm.c: 2495: (snd_pcm_open_noupdate) Неизвестный PCM cards.pcm.rear
ALSA lib pcm.c: 2495: (snd_pcm_open_noupdate) Неизвестный PCM cards.pcm.center_lfe
ALSA lib pcm.c: 2495: (snd_pcm_open_noupate)PCM cards.pcm.side
ALSA lib pcm_route.c: 867: (find_matching_chmap) Не найдено подходящей карты каналов
ALSA lib pcm_dmix.c: 1052: (snd_pcm_dmix_open) невозможно открыть ведомое устройство
, и он продолжает поднимать это:
ALSA lib pcm.c: 8306: (snd_pcm_recover) произошел опустошение "
Я получаю их в Server.py, который получает и воспроизводит звук. Как это исправить?
Сервер:
import pyaudio
import wave
from time import sleep
import socket
import threading
IP = "127.0.0.1"
PORT = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((IP, PORT))
s.listen()
class Voice:
def __init__(self):
self.p = pyaudio.PyAudio()
def get_input_devices(p):
info = p.get_host_api_info_by_index(0)
numdevices = info.get("deviceCount")
for i in range(0, numdevices):
if (
p.get_device_info_by_host_api_device_index(0, i).get(
"maxInputChannels"
)
) > 0:
print(
"Input Device id ",
i,
" - ",
p.get_device_info_by_host_api_device_index(0, i).get("name"),
)
print("---- list of devices ")
get_input_devices(self.p)
print("--------------------")
self.DEV_INDEX = int(input("Index: "))
self.RATE = int(
self.p.get_device_info_by_index(self.DEV_INDEX)["defaultSampleRate"]
)
self.CHUNK = 1024
self.FORMAT = pyaudio.paInt16
self.CHANNELS = 2
self.client, self.addr = s.accept()
# threading.Thread(target=self.sending).start()
threading.Thread(target=self.receiving).start()
def sending(self):
streamRecored = self.p.open(
format=self.FORMAT,
channels=self.CHANNELS,
rate=self.RATE,
input=True,
frames_per_buffer=self.CHUNK,
input_device_index=self.DEV_INDEX,
)
print("RECORDING")
while True:
data = streamRecored.read(self.CHUNK, exception_on_overflow=False)
self.client.send(data)
print("DONE RECORDING")
streamRecored.stop_stream()
streamRecored.close()
def receiving(self):
stream = self.p.open(
format=self.FORMAT,
channels=self.CHANNELS,
rate=self.RATE,
output=True,
frames_per_buffer=self.CHUNK,
)
while True:
data = self.client.recv(1024)
stream.write(data)
stream.stop_stream()
stream.close()
if __name__ == "__main__":
Voice()
Клиент:
import pyaudio
import wave
from time import sleep
import socket
import threading
IP = "127.0.0.1"
PORT = 5000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((IP, PORT))
class Voice:
def __init__(self):
self.p = pyaudio.PyAudio()
def get_input_devices(p):
info = p.get_host_api_info_by_index(0)
numdevices = info.get("deviceCount")
for i in range(0, numdevices):
if (
p.get_device_info_by_host_api_device_index(0, i).get(
"maxInputChannels"
)
) > 0:
print(
"Input Device id ",
i,
" - ",
p.get_device_info_by_host_api_device_index(0, i).get("name"),
)
print("---- list of devices ")
get_input_devices(self.p)
print("--------------------")
self.DEV_INDEX = int(input("Index: "))
self.RATE = int(
self.p.get_device_info_by_index(self.DEV_INDEX)["defaultSampleRate"]
)
self.CHUNK = 1024
self.FORMAT = pyaudio.paInt16
self.CHANNELS = 2
threading.Thread(target=self.sending).start()
# threading.Thread(target=self.receiving).start()
def sending(self):
streamRecored = self.p.open(
format=self.FORMAT,
channels=self.CHANNELS,
rate=self.RATE,
input=True,
frames_per_buffer=self.CHUNK,
input_device_index=self.DEV_INDEX,
)
print("RECORDING")
while True:
data = streamRecored.read(self.CHUNK, exception_on_overflow=False)
s.send(data)
print("DONE RECORDING")
streamRecored.stop_stream()
streamRecored.close()
def receiving(self):
stream = self.p.open(
format=self.FORMAT,
channels=self.CHANNELS,
rate=self.RATE,
output=True,
frames_per_buffer=self.CHUNK,
)
while True:
data = s.recv(1024)
stream.write(data)
stream.stop_stream()
stream.close()
Voice()