我正在尝试使用 python 将数据写入虚拟音频电缆。到目前为止,我并不真正关心我使用哪个模块,所以我尝试了 PyAudio 和 Sounddevive。我从 VB-Audio 安装了虚拟电缆。它确实显示在我的设备列表中。一旦我想用电缆初始化输出流,就会出现问题。出现错误:OSError: [Errno -9998] 通道数无效
检查设备列表,我拥有的电缆选项的索引和通道数是:
3 线输出(VB-Audio Virtual,MME(2 输入,0 输出)
9 CABLE 输入(VB-Audio Virtual C,MME(0 输入,2 输出)
9 CABLE 输入(VB-Audio Virtual C,MME(0 输入,2 输出)
20 线输入(VB-音频虚拟线),Windows DirectSound(0 输入,2 输出)
24 CABLE 输入(VB-音频虚拟电缆),Windows WASAPI(0 输入,2 输出)
28 CABLE 输出(VB-音频虚拟电缆),Windows WASAPI(2 输入,0 输出)
35 线输出(VB-音频点),Windows WDM-KS(8 输入,0 输出)
本能地我想写入电缆输入。但不知何故,输入没有可用的输入通道?直接使用具有正确通道数的输出通道也会引发相同的错误。知道我能做什么吗?
import numpy as np
import soundcard as sc
import soundfile as sf
import sounddevice as sd
import pyaudio
# Initialize PyAudio
p = pyaudio.PyAudio()
buffer_size = 512
# set devices to in- and output from
mic_input_index = 1
input_sample_rate = int(sd.query_devices(mic_input_index)['default_samplerate'])
v_cable_output_index = 14
# Open an audio stream for input
input_stream = p.open(format=pyaudio.paInt16,
channels=2,
rate=input_sample_rate,
input=True,
frames_per_buffer=buffer_size,
input_device_index=mic_input_index)
# Open an audio stream for output (virtual audio device)
output_stream = p.open(format=pyaudio.paInt16,
channels=8,
rate=input_sample_rate,
output=True,
output_device_index=v_cable_output_index)
while True:
try:
# Read audio data
data = input_stream.read(buffer_size)
audio_array = np.frombuffer(data, dtype=np.int16)
processed_audio = audio_array
# Play the processed audio to the virtual audio device
output_stream.write(processed_audio.tobytes())
except KeyboardInterrupt:
break
遇到同样的错误,有什么想法吗??