ALSA 또는 PulseAudio를 사용하여 두 개의 USB 마이크를 하나의 스트림으로 결합

ALSA 또는 PulseAudio를 사용하여 두 개의 USB 마이크를 하나의 스트림으로 결합

이것은 나에게도 매우 새로운 질문이며 질문은 간단하거나 어리석을 수 있습니다.

PC에 2개의 USB 마이크(스피커 포함)가 연결되어 있습니다. 아래의 카드 2와 카드 3입니다.

arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: USB [Jabra SPEAK 410 USB], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 3: USB_1 [Jabra SPEAK 510 USB], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

이를 결합된 스트림으로 병합하고 이 출력을 기본 마이크 스트림으로 지정하고 싶습니다(나중에 Google Assistant SDK에서 사용하고 싶습니다).

ALSA이것이 Google이 기대하는 방식인 것 같기 때문에 이 작업을 수행해야 합니다 .

.asoundrc내 홈 디렉터리에 다음 내용으로 파일을 만들었습니다.

pcm.multitest {
    type multi

    slaves.a.pcm "hw:2,0"
    slaves.a.channels 2
    slaves.b.pcm "hw:3,0"
    slaves.b.channels 2

    bindings.0.slave a
    bindings.0.channel 0
    bindings.1.slave a
    bindings.1.channel 1
    bindings.2.slave b
    bindings.2.channel 0
    bindings.3.slave b
    bindings.3.channel 1
}

내용이 맞는지 확인하는 방법과 테스트하는 방법을 잘 모르겠습니다. alsa-state.service 재시작을 테스트했지만 출력이 어떻게 될지 잘 모르겠습니다. 따라해보려고 해요이 문서하지만 사전 지식 없이는 내가 올바른 길을 가고 있는지 알기가 어렵습니다.

pactl나는 다음에서 찾은 스크립트를 사용하여 동일한 기능을 달성하려고 했습니다.또 다른 문제.

스크립트는 결합된 채널을 성공적으로 생성했지만 Audacity와 같은 애플리케이션을 열면 결합된 채널이 나열되지 않으므로 여기서도 약간 혼란스럽습니다.

#!/bin/bash

#    Script to map two pulseaudio hardware input sources as mono inputs
#    to left and right channel of a new loopback-sink respectively. This
#    sink can be used e.g. to use VoIP or record two microphones seperately.
#    Copyright (C) 2013, Henning Hollermann, [email protected]
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

do_activate() {
    while [ "x" = "x$LEFT" ]; do
        echo "Choose Source for left channel by ID"
        pactl list short sources
        read ID
        LEFT=$(pactl list short sources|awk '/^'$ID'/{print $2}')
    done
    while [ "x" = "x$RIGHT" ]; do
        echo "Choose Source for right channel by ID"
        pactl list short sources | grep -v $LEFT
        read ID
        RIGHT=$(pactl list short sources | grep -v $LEFT|awk '/^'$ID'/{print $2}')
    done
    # Create the name of the Combined sink
    NAME="Combined_Mics:_Left:_"$(echo $LEFT|awk -F'.' '$0=$2')"_Right:_"$(echo $RIGHT|awk -F'.' '$0=$2')

    echo "[LOAD] null sink as \"$NAME\" to connect the two mics to"
    pactl load-module module-null-sink \
            sink_name=combined channels=2 \
            sink_properties="device.description=$NAME"

    echo "[LOAD] map source 1 ($LEFT) to left channel of \"$NAME\""
    pactl load-module module-remap-source \
            source_name=${LEFT}_left_channel master=$LEFT channels=2 \
            master_channel_map=mono,mono channel_map=left,left
    pactl load-module module-loopback sink=combined source=${LEFT}_left_channel

    echo "[LOAD] map source 2 ($RIGHT) to right channel of \"$NAME\""
    pactl load-module module-remap-source \
            source_name=${RIGHT}_right_channel master=$RIGHT channels=2 \
            master_channel_map=mono,mono channel_map=right,right
    pactl load-module module-loopback sink=combined source=${RIGHT}_right_channel
    echo "[DONE] Now adjust the left and right channel volume of the new sink to be equally loud"


}

do_deactivate() {
    echo "[UNLOAD] pulseaudio modules..."
    echo "[UNLOAD] module-loopback"
    pactl unload-module module-loopback
    echo "[UNLOAD] module-remap-source"
    pactl unload-module module-remap-source
    echo "[UNLOAD] module-null-sink"
    pactl unload-module module-null-sink
}

init() {
    for exe in /usr/bin/pulseaudio /usr/bin/pactl; do
        if [ ! -x "$exe" ]; then
            echo "[ERROR] required file $exe not found or not executable"
            exit 1
        fi
    done
    [ ! -x /usr/bin/pavucontrol ] && echo "[NOTICE] pavucontrol might be very useful."
}

# MAIN
init;
case $1 in
activate|enable|start)
    do_activate;;
deactivate|disable|stop)
    do_deactivate;;
*)
    echo "Usage: $0 [enable|disable]";;
esac;

관련 정보