如何从特定 PC 列出/访问 USB 声卡的所有可用音频输入和输出端口/通道

如何从特定 PC 列出/访问 USB 声卡的所有可用音频输入和输出端口/通道

在 Windows 7 中,我曾经使用派美达,一个 Python 库,用于列出可用的接口以及使用它们来播放和录制音频。典型的查询如下所示:

声音

现在,我不再使用 Windows 7,因为我已经迁移到 Ubuntu 16.04。因此,我使用 ALSA 命令查看可用的音频接口。以下是相同的输出:

skrowten_hermit@PC-760:~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: AD1984A Analog [AD1984A Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 2: AD1984A Alt Analog [AD1984A Alt Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Eight [M-Track Eight], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
skrowten_hermit@PC-760:~$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Intel [HDA Intel], device 0: AD1984A Analog [AD1984A Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 2: AD1984A Alt Analog [AD1984A Alt Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Eight [M-Track Eight], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

我们可以看到,我的外置声卡 M-Audio 在这里被列为 ALSA 卡,这意味着它被正确检测到。现在,当我阅读与 ALSA 相关的文章时,我了解了设备,然后使用-L查看可用的设备如下:

skrowten_hermit@PC-760:~$ aplay -L
default
    Playback/recording through the PulseAudio sound server
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
sysdefault:CARD=Intel
    HDA Intel, AD1984A Analog
    Default Audio Device
front:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Front speakers
surround21:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
dmix:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Direct sample mixing device
dmix:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Direct sample mixing device
dsnoop:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Direct sample snooping device
dsnoop:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Direct sample snooping device
hw:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Direct hardware device without any conversions
hw:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Direct hardware device without any conversions
plughw:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Hardware device with all software conversions
plughw:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Hardware device with all software conversions
sysdefault:CARD=Eight
    M-Track Eight, USB Audio
    Default Audio Device
front:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Front speakers
surround21:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Direct sample mixing device
dsnoop:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Direct sample snooping device
hw:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Direct hardware device without any conversions
plughw:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Hardware device with all software conversions
skrowten_hermit@PC-760:~$ arecord -L
default
    Playback/recording through the PulseAudio sound server
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
sysdefault:CARD=Intel
    HDA Intel, AD1984A Analog
    Default Audio Device
front:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Front speakers
surround21:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
dmix:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Direct sample mixing device
dmix:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Direct sample mixing device
dsnoop:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Direct sample snooping device
dsnoop:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Direct sample snooping device
hw:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Direct hardware device without any conversions
hw:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Direct hardware device without any conversions
plughw:CARD=Intel,DEV=0
    HDA Intel, AD1984A Analog
    Hardware device with all software conversions
plughw:CARD=Intel,DEV=2
    HDA Intel, AD1984A Alt Analog
    Hardware device with all software conversions
sysdefault:CARD=Eight
    M-Track Eight, USB Audio
    Default Audio Device
front:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Front speakers
surround21:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Direct sample mixing device
dsnoop:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Direct sample snooping device
hw:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Direct hardware device without any conversions
plughw:CARD=Eight,DEV=0
    M-Track Eight, USB Audio
    Hardware device with all software conversions

上面的内容与我的预期有些不同(我希望获得频道标识符,但最终得到的参数如下系统默认正面环绕21侦查员硬件等等)。我的声卡有 8 对 I/O。因此,我期望的是通道/端口标识符或类似的东西。

在网上搜索了一番之后,我偶然发现了pyAudio声音设备python 库。前者给出以下输出:

skrowten_hermit@PC-760:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyaudio
>>> p = pyaudio.PyAudio()
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
Cannot open PortAudio client
JackShmReadWritePtr1::~JackShmReadWritePtr1 - Init not done for 4294967295, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock
>>> for i in range(p.get_device_count()):
...     print p.get_device_info_by_index(i).get('name')
...
HDA Intel: AD1984A Analog (hw:0,0)
HDA Intel: AD1984A Alt Analog (hw:0,2)
M-Track Eight: USB Audio (hw:1,0)
sysdefault
pulse
default
>>> import pyaudio
>>> p = pyaudio.PyAudio()
>>> for i in range(p.get_device_count()):
...     print p.get_device_info_by_index(i)
...
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': 0.008707482993197279, 'maxInputChannels': 2L, 'structVersion': 2L, 'hostApi': 0L, 'index': 0, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': u'HDA Intel: AD1984A Analog (hw:0,0)', 'defaultHighInputLatency': 0.034829931972789115}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': -1.0, 'defaultLowInputLatency': 0.008707482993197279, 'maxInputChannels': 2L, 'structVersion': 2L, 'hostApi': 0L, 'index': 1, 'defaultHighOutputLatency': -1.0, 'maxOutputChannels': 0L, 'name': u'HDA Intel: AD1984A Alt Analog (hw:0,2)', 'defaultHighInputLatency': 0.034829931972789115}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': 0.008707482993197279, 'maxInputChannels': 8L, 'structVersion': 2L, 'hostApi': 0L, 'index': 2, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 8L, 'name': u'M-Track Eight: USB Audio (hw:1,0)', 'defaultHighInputLatency': 0.034829931972789115}
{'defaultSampleRate': 48000.0, 'defaultLowOutputLatency': 0.021333333333333333, 'defaultLowInputLatency': 0.021333333333333333, 'maxInputChannels': 128L, 'structVersion': 2L, 'hostApi': 0L, 'index': 3, 'defaultHighOutputLatency': 0.021333333333333333, 'maxOutputChannels': 128L, 'name': u'sysdefault', 'defaultHighInputLatency': 0.021333333333333333}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 4, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': u'front', 'defaultHighInputLatency': -1.0}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 5, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': u'surround40', 'defaultHighInputLatency': -1.0}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 6, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': u'surround51', 'defaultHighInputLatency': -1.0}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 7, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': u'surround71', 'defaultHighInputLatency': -1.0}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': 0.008707482993197279, 'maxInputChannels': 32L, 'structVersion': 2L, 'hostApi': 0L, 'index': 8, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 32L, 'name': u'pulse', 'defaultHighInputLatency': 0.034829931972789115}
{'defaultSampleRate': 48000.0, 'defaultLowOutputLatency': 0.021333333333333333, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 9, 'defaultHighOutputLatency': 0.021333333333333333, 'maxOutputChannels': 2L, 'name': u'dmix', 'defaultHighInputLatency': -1.0}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.008707482993197279, 'defaultLowInputLatency': 0.008707482993197279, 'maxInputChannels': 32L, 'structVersion': 2L, 'hostApi': 0L, 'index': 10, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 32L, 'name': u'default', 'defaultHighInputLatency': 0.034829931972789115}

上面的内容也不够令人满意。仔细查看设备列表的枚举输出可以发现,对应于‘名称’:u‘M-Track Eight:USB 音频 (hw:1,0)’确实显示输入和输出通道数为 8,但列为单个设备。然后,sounddevice 给了我以下输出:

skrowten_hermit@PC-760:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sounddevice as sd
>>> sd.query_devices()
   0 HDA Intel: AD1984A Analog (hw:0,0), ALSA (2 in, 2 out)
   1 HDA Intel: AD1984A Alt Analog (hw:0,2), ALSA (2 in, 0 out)
   2 M-Track Eight: USB Audio (hw:1,0), ALSA (8 in, 8 out)
   3 sysdefault, ALSA (128 in, 128 out)
   4 front, ALSA (0 in, 2 out)
   5 surround40, ALSA (0 in, 2 out)
   6 surround51, ALSA (0 in, 2 out)
   7 surround71, ALSA (0 in, 2 out)
   8 pulse, ALSA (32 in, 32 out)
   9 dmix, ALSA (0 in, 2 out)
* 10 default, ALSA (32 in, 32 out)

这里,设备 2 也显示 8 输入,8 输出。

我不明白的是:

  1. 什么时候pyaudio声音设备可以看到我的声卡有 8 对 I/O 通道,为什么他们没有将它们列为单独的设备?
  2. 而 ALSA 根本看不到这一点(这是使用 ALSA 命令的基本要求玩耍或者一个记录)?
  3. 或者,即使我理解设备对应于物理模拟通道/端口(我将在其中连接设备),这是正确的吗?
  4. 这是驱动程序的限制吗?

我的要求简而言之:

  1. 我应该能够将音频播放到我的(任何)输入端口M-Audio M-Track Eight声卡并录制以及从我的(任何)输出端口播放音频M-Audio M-Track Eight声卡并播放。 M-Audio M-Track Eight 描述
  2. 我应该能够使用上面提到的 ALSA 命令来播放和录制。
  3. 我应该能够在单独的线程中播放和录制。

我该如何实现这一点?我能更清楚地了解 ALSA 及其在这里的作用吗?有没有可以满足我要求的驱动程序?


更新:

~/.asoundrc我根据收到的输入创建了以下内容:

pcm.!default {
    type plug
    slave {
       pcm "hw:1,0"
    }
}

ctl.!default {
    type hw
    card 1
}

pcm_slave.eightchannels {
    pcm "hw:1,0"
    channels 8
    rate 44100
    buffer_size 4096
    period_size 2048
}

pcm.ch12 {
    type asym
    playback.pcm {
        type dshare
        ipc_key 1111
        slave eightchannels
        bindings [ 0 1 ]
    }
    capture.pcm {
        type dsnoop
        ipc_key 1111
        slave eightchannels
        bindings [ 0 1 ]
    }
    hint.description "M-Audio channels 1,2"
}
pcm.ch34 {
    type asym
    playback.pcm {
        type dshare
        ipc_key 2222
        slave eightchannels
        bindings [ 2 3 ]
    }
    capture.pcm {
        type dsnoop
        ipc_key 2222
        slave eightchannels
        bindings [ 2 3 ]
    }
    hint.description "M-Audio channels 3,4"
}

因此,通过上述配置,当我尝试运行时aplay,我收到以下内容:

skrowten_hermit@PC-760:~$ aplay -D ch12 -c 1 -r 8000 male_8k.wav
Playing WAVE 'male_8k.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
aplay: set_params:1233: Sample format non available
Available formats:
- S32_LE

假设它与所示格式不匹配,我尝试将格式作为参数传递,aplay如下所示:

skrowten_hermit@PC-760:~$ aplay -D ch12 -c 1 -r 8000 -f S32_LE male_8k.wav
Warning: format is changed to S16_LE
Playing WAVE 'male_8k.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
aplay: set_params:1233: Sample format non available
Available formats:
- S32_LE

.wav这个错误与 PCM 设备或正在播放的文件有关吗?

附言:.!defaults 是后来添加的。删除它们没有任何区别!

答案1

这四对没有列为单独的设备,因为它们不是单独的设备。M-Track Eight 是一个具有八个通道的单一设备。

可以创建一组模拟四对立体声的虚拟软件设备。为此,请将类似以下内容添加到/etc/asound.conf或您的~/.asoundrc

pcm_slave.eightchannels {
    pcm "hw:Eight"
    channels 8
    rate 48000
    buffer_size 8192  # make these sizes smaller for lower latency
    period_size 2048
}

pcm.ch12 {
    type asym
    playback.pcm {
        type dshare
        ipc_key 2222      # some random number, but the same for the same slave
        slave eightchannels
        bindings [ 0 1 ]
    }
    capture.pcm {
        type dsnoop
        ipc_key 2222
        slave eightchannels
        bindings [ 0 1 ]
    }
    hint.description "M-Track channels 1,2"
}
pcm.ch34 {
    type asym
    playback.pcm {
        type dshare
        ipc_key 2222
        slave eightchannels
        bindings [ 2 3 ]
    }
    capture.pcm {
        type dsnoop
        ipc_key 2222
        slave eightchannels
        bindings [ 2 3 ]
    }
    hint.description "M-Track channels 3,4"
}
...

答案2

经过多次尝试和插件实验后,我终于找到了上述问题的解决方案。它只是上述答案和我从中得到的提示的延伸这里。首先,以下是.asoundrc我用来使其工作的方法:

pcm.!default {
    type plug
    slave {
       pcm "hw:1,0"
    }
}

ctl.!default {
    type hw
    card 1
}

pcm_slave.m-audio_m-track_eight_1 {
    pcm "hw:1,0"
    channels 8
    rate 44100
    buffer_size 4096
    period_size 1024
}

pcm.outch1 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 0 ]
    hint.description "M-Audio M-Track Eight output/playback channel 1"
}

pcm.inch1 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 0 ]
    hint.description "M-Audio M-Track Eight input/capture channel 1"
}

pcm.outch2 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 1 ]
    hint.description "M-Audio M-Track Eight output/playback channel 2"
}

pcm.inch2 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 1 ]
    hint.description "M-Audio M-Track Eight input/capture channel 2"
}

pcm.outch3 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 2 ]
    hint.description "M-Audio M-Track Eight output/playback channel 3"
}

pcm.inch3 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 2 ]
    hint.description "M-Audio M-Track Eight input/capture channel 3"
}

pcm.outch4 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 3 ]
    hint.description "M-Audio M-Track Eight output/playback channel 4"
}

pcm.inch4 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 3 ]
    hint.description "M-Audio M-Track Eight input/capture channel 4"
}

pcm.outch5 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 4 ]
    hint.description "M-Audio M-Track Eight output/playback channel 5"
}

pcm.inch5 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 4 ]
    hint.description "M-Audio M-Track Eight input/capture channel 5"
}

pcm.outch6 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 5 ]
    hint.description "M-Audio M-Track Eight output/playback channel 6"
}

pcm.inch6 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 5 ]
    hint.description "M-Audio M-Track Eight input/capture channel 6"
}

pcm.outch7 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 6 ]
    hint.description "M-Audio M-Track Eight output/playback channel 7"
}

pcm.inch7 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 6 ]
    hint.description "M-Audio M-Track Eight input/capture channel 7"
}

pcm.outch8 {
    type dshare
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 7 ]
    hint.description "M-Audio M-Track Eight output/playback channel 8"
}

pcm.inch8 {
    type dsnoop
    ipc_key 1111
    slave m-audio_m-track_eight_1
    bindings [ 7 ]
    hint.description "M-Audio M-Track Eight input/capture channel 8"
}

我试图让整个过程保持简单。ALSA 命令aplayarecord分别是命令行声音播放器和录音机,它们允许我执行所需的操作,即播放语音文件以及在一个通道(连接到模拟输出端口)播放语音文件并使用另一个单声道(连接到模拟输入端口)录制它。

为了测试配置文件,我使用了以下aplay命令:

skrowten_hermit@PC-760:~$ aplay -D plug:outch1 -c 1 -r 8000 male_8k.wav

有了上述内容,播放就可以正常工作了。现在,为了开始工作,并查看播放和捕获是否正常工作,使用了以下内容:

skrowten_hermit@PC-760:~$ aplay -D plug:outch1 -c 1 -r 8000 /home/sreekanth/Downloads/male_8k.wav | arecord -D plug:inch2 -c 1 -r 8000 -d 10 /home/sreekanth/Downloads/out_12.wav

以上使用通道 1(连接到我的 M-Audio M-Track Eight 声卡上的模拟输出端口 1)作为播放设备,通道 2(连接到我的 M-Audio M-Track Eight 声卡上的模拟输入端口 2)作为录音设备。要使用其他设备,出局1可以替换为输出2出局3出局4出局5出局6出局7出局8英寸2通过任何英寸1英寸3英寸4英寸5英寸6英寸7英寸8(根据 中的定义.asoundrc)。

找到正确且有据可查的 ALSA 文献有点困难。但根据我的经验,它是bindings您需要调整的参数,以便将音频从模拟端口(可能是客户端通道)路由到 ALSA 通道(如上文中定义的从属通道.asoundrc)。

相关内容