我试图在python中使用socket和pyaudio编写一个语音聊天的代码。我写了它,它可以工作,但它产生了以下的错误
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open)无法打开奴隶。
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) 未知PCM卡.pcm.area
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) 未知PCM卡.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) 未知PCM卡.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中得到这些。如何解决这个问题?
Server:
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):
p.get_device_info_by_host_api_device_index(0, i).get(
"maxInputChannels"
print(
"Input Device id ",
" - ",
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()
Client:
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):
p.get_device_info_by_host_api_device_index(0, i).get(
"maxInputChannels"
print(
"Input Device id ",
" - ",
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()