Reading soundcard output with python
我已经成功地利用pyaudio来读取和记录麦克风数据。 我想对声卡输出做同样的事情。 (即播放wavfile并使用pyaudio打开流,并逐帧读取声卡输出)。
为了阅读麦克风,我打开了一个pyaudio流,如下所示
1 2 3 4 5 6 | stream = pyaud.open( format = pyaudio.paInt16, channels = 1, rate = 22050, input_device_index = 0, input = True) |
当我将input_device_index更改为1时,出现以下错误
IOError:[Errno无效的通道数] -9998
以下是Macbook声卡的system_info
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | Default Devices: ================ Default Input Device : 0 defaultSampleRate: 44100.0 defaultLowOutputLatency: 0.01 defaultLowInputLatency: 0.00199546485261 maxInputChannels: 2 structVersion: 2 hostApi: 0 (Core Audio) index: 0 defaultHighOutputLatency: 0.1 maxOutputChannels: 0 name: Built-in Microph defaultHighInputLatency: 0.0121541950113 -------------------------------- Default Output Device: 1 defaultSampleRate: 44100.0 defaultLowOutputLatency: 0.00655328798186 defaultLowInputLatency: 0.01 maxInputChannels: 0 structVersion: 2 hostApi: 0 (Core Audio) index: 1 defaultHighOutputLatency: 0.0167120181406 maxOutputChannels: 2 name: Built-in Output defaultHighInputLatency: 0.1 -------------------------------- |
某些声卡具有"捕获"通道,这是声卡的输出。 它们可能无法正常工作(音乐行业似乎迫切要求消除这些端口)。
以下是针对Linux的...例如。 在我的系统上,我只有一个标准的板载ALC887音频端口。 在/ proc / asound / card0中,我找到了一个端口pcm2c,该端口具有以下信息:
1 2 3 4 5 6 7 8 9 10 11 | card: 0 device: 2 subdevice: 0 stream: CAPTURE id: ALC887-VD Alt Analog name: ALC887-VD Alt Analog subname: subdevice #0 class: 0 subclass: 0 subdevices_count: 1 subdevices_avail: 1 |
这些捕获设备应显示在您的音频混音器中。