ALSA lib pcm.c:8306:(snd_pcm_recover) 发生欠载

Mia*_*bdi 8 python sockets pyaudio

我正在尝试在 python 中使用 socket 和 pyaudio 编写语音聊天。我写了它并且它有效,但它引发了这些错误

ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) 无法打开从站

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) 未知 PCM 卡.pcm.rear

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 中得到这些。如何解决?

服务器:

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()

Run Code Online (Sandbox Code Playgroud)

客户:

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()

Run Code Online (Sandbox Code Playgroud)