Answers:
大多数GUI工具包使用相同的后端PulseAudio。使用pactl
写控制脚本。
NAME
pactl - Control a running PulseAudio sound server
DESCRIPTION
pactl can be used to issue control commands to the PulseAudio sound server.
pactl only exposes a subset of the available operations. For the full set use the pacmd(1).
资源: man pactl
检查可用的输出接收器
$ pactl list short sinks
0 alsa_output.pci-0000_01_00.1.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
1 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
检查可用的输入源
$ pactl list short sources
0 alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
1 alsa_output.pci-0000_00_1b.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
2 alsa_input.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
检查默认值
$ pactl info
Server String: /run/user/1000/pulse/native
Library Protocol Version: 30
Server Protocol Version: 30
Is Local: yes
Client Index: 2
Tile Size: 65472
User Name: user
Host Name: userpc
Server Name: pulseaudio
Server Version: 6.0
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: alsa_output.pci-0000_00_1b.0.analog-stereo
Default Source: alsa_input.pci-0000_00_1b.0.analog-stereo
设置默认值
pactl set-default-source id-or-name
pactl set-default-sink id-or-name
例:
pactl set-default-source alsa_input.pci-0000_00_1b.0.analog-stereo
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
要么:
pactl set-default-source 2
pactl set-default-sink 1
笔记:
这只会影响新的流,你必须移动当前正在运行的流,所以使用:
pacmd move-sink-input <stream-id> <sink-id/name>
有些卡有多个可切换端口,可能是您想要的不是默认端口。
检查可用端口:
$pactl list sinks
Sink #1
State: RUNNING
Name: alsa_output.pci-0000_00_1b.0.analog-stereo
Description: Built-in Audio Analog Stereo
Driver: module-alsa-card.c
...
Ports:
analog-output-speaker: Speakers (priority: 10000, not available)
analog-output-headphones: Headphones (priority: 9000, available)
Active Port: analog-output-headphones
Formats:
pcm
...
设置它:
pactl set-sink-port <sink-id/name> <port-name>
例:
pactl set-sink-port 1 analog-output-headphones
要更改主频道
在本教程之后,您可以使用qdbus
以下方式设置主通道:
使用以下命令查找每个设备的主混音器。首先手动将主通道设置为要检查的主通道,然后运行命令:
qdbus org.kde.kmix /Mixers org.kde.KMix.MixSet.currentMasterControl
使用该命令的结果和您希望控制的音频接收器,使用以下语法更改主通道:
qdbus org.kde.kmix /Mixers org.kde.KMix.MixSet.setCurrentMaster "[insert Mixer]" "[insert sink]" 2>&1 > /dev/null
最后,将所有当前音频切换到新通道,将其设置为默认通道并将其设置为主通道的脚本如下所示:
#!/bin/bash
pactl set-default-sink alsa_output.usb-Logitech_Logitech_G930_Headset-00-Headset.analog-stereo
pactl set-default-source alsa_input.usb-Logitech_Logitech_G930_Headset-00-Headset.analog-mono
INPUTS=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))
for i in ${INPUTS[*]}; do pacmd move-sink-input $i alsa_output.usb-Logitech_Logitech_G930_Headset-00-Headset.analog-stereo &> /dev/null; done
qdbus org.kde.kmix /Mixers org.kde.KMix.MixSet.setCurrentMaster "PulseAudio::Playback_Devices=:1" "alsa_output.usb-Logitech_Logitech_G930_Headset-00-Headset.analog-stereo" 2>&1 > /dev/null
pavucontrol
然后在屏幕上打开3(终端w / pactl + pavucontrol面板+ phonon面板)。尝试更改每个设置并观看。有时,你需要关闭声子再次打开它以查看真实的设置状态。
pactl list short sinks
,请参阅下面的答案
由于这个答案,我终于找到了解决方案,请参阅以下说明
在混合中始终显示HDMI输出 我们将创建一个新的配置文件,链接两个配置文件“模拟音频”和“HDMI音频”。
根据我的理解,此文件
/usr/share/pulseaudio/alsa-mixer/profile-sets/default.conf
列出了Alsa和Pulseaudio之间的所有映射配置文件。
1.
查找涉及您的映射Analog profile
和HDMI profile
定义。(说明:应与Audio Volume Kde设置模块中显示的设备配置文件相匹配)
对我来说如下:
[Mapping analog-stereo]
device-strings = front:%f
channel-map = left,right
paths-output = analog-output analog-output-lineout analog-output-speaker analog-output-headphones analog-output-headphones-2
paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line analog-input-headphone-mic analog-input-headset-mic
priority = 10
[Mapping hdmi-stereo-extra1]
description = Digital Stereo (HDMI 2)
device-strings = hdmi:%f,1
paths-output = hdmi-output-1
channel-map = left,right
priority = 2
direction = output
2.
在上面的映射定义的基础上,我创建了以下新的配置文件,它们将上述两个组合在一起:
[Profile output:analog-stereo+output:hdmi-stereo-extra1]
description = All
output-mappings = analog-stereo hdmi-stereo-extra1
input-mappings = analog-stereo
3.
使用以下命令重新启动脉冲音频:
pulseaudio --kill; sleep 1; pulseaudio --start
4.
转到KDE声子设置>音频硬件设置,然后选择新配置文件。
现在你应该在混合中看到两个配置文件,这样你就可以轻松切换:
我建议使用这种等离子体混合器:https://store.kde.org/p/1100894/
(额外步骤)强制启用两个输出
如果您不介意同时使用计算机扬声器和电视输出音频(因此基本上您不必再切换音频输出)。
您可以选择以下设置,然后您将在调音台中输入新条目
在之前的评论的基础上,我编写了以下脚本并将其绑定到热键,以便在KDE Plasma中用于在我的两个音频设备之间切换。我喜欢控制我的音频源,而不是完全自动化这个过程。
根据需要更改音频设备。使用pactl list short sinks
以确定您的设备。
#!/bin/bash
# Audio sinks
HEADSET='alsa_output.usb-Corsair_Corsair_VOID_PRO_Wireless_Gaming_Headset-00.analog-stereo'
SPEAKERS='alsa_output.pci-0000_1f_00.3.analog-stereo'
# Get current audio sink
CURRENTDEV=$(pactl list short sinks | grep RUNNING | awk {'print $2'})
# Determine our next audio sink
if [[ "$CURRENTDEV" == "$HEADSET" ]]; then
NEXTDEV=$SPEAKERS
else
NEXTDEV=$HEADSET
fi
# Set our default device
pactl set-default-sink $NEXTDEV
# Move current streams (dont check for null, if null you wont see heads up display of audio change)
INPUTS=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))
for i in ${INPUTS[*]}; do pacmd move-sink-input $i $NEXTDEV &> /dev/null; done