gpt4 book ai didi

python - Raspberry ALSA 声音输出/输入从机

转载 作者:太空宇宙 更新时间:2023-11-03 12:59:38 25 4
gpt4 key购买 nike

我正在尝试将一台设备设置为播放,将另一台设备设置为捕获,我的 nano/etc/asound.conf 有这个:

pcm.!default {
type asym
playback.pcm "plughw:1,1"
capture.pcm "plughw:1,0"
}

ctl.!default {
type hw
card 0
}

我可以完美地播放声音,但我无法录制声音,我的 python 代码抛出此错误:

ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) 
unable to open slave
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side

ALSA lib pcm.c:2217:(snd_pcm_open_noupdate)
Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open)
The dmix plugin supports only playback stream

ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open)
unable to open slave

这是我正在运行的代码的一部分:

import pyaudio
class Microphone(AudioSource):
def __init__(self, device_index = None):
self.device_index = device_index
self.format = pyaudio.paInt16 # 16-bit int sampling
self.SAMPLE_WIDTH = pyaudio.get_sample_size(self.format)
self.RATE = 16000 # sampling rate in Hertz
self.CHANNELS = 1 # mono audio
self.CHUNK = 1024 # number of frames stored in each buffer

self.audio = None
self.stream = None

def __enter__(self):
self.audio = pyaudio.PyAudio()
self.stream = self.audio.open(
input_device_index = self.device_index,
format = self.format, rate = self.RATE, channels = self.CHANNELS, frames_per_buffer = self.CHUNK,
input = True, # stream is an input stream
)
return self

def __exit__(self, exc_type, exc_value, traceback):
self.stream.stop_stream()
self.stream.close()
self.stream = None
self.audio.terminate()

我该如何解决这个错误?

提前谢谢你。

最佳答案

pyaudio 基于 PortAudio ;所有这些愚蠢的消息都是因为 PortAudio 试图枚举音频设备。

pyaudio 设备索引不一定与 ALSA 卡索引相同。使用 get_device_count()get_device_info_by_index()找到要使用的输入设备。

关于python - Raspberry ALSA 声音输出/输入从机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27053373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com