除了扬声器和普通麦克风外,我还有一套不错的无线耳机,我不时使用。
我想编写一个脚本,以在一个输入和输出源与另一个输入和输出源之间进行切换,本质上是在耳机和扬声器+麦克风之间进行切换。
我想在这之间进行更改:
...和这个:
我有办法脚本在两个输入和输出之间进行转换吗?本质上,我正在寻找这样的东西:
CURRENT_INPUT="$(get-current-input-name)"
CURRENT_OUTPUT="$(get-current-output-name)"
if [ "$CURRENT_INPUT" == "Vengeance 2000" ]; then
set-current-input "HD Pro Webcam C920"
else
set-current-input "Vengeance 2000"
fi
if ["$CURRENT_OUTPUT" == "Vengeance 2000" ]; then
set-current-output "Built-in Audio"
else
set-current-output "Vengeance 2000"
fi
有没有办法编写这个脚本?
正如@ Teresa-e-Junior指出的pactl
是要使用的工具:
首先,我们可能想要获取PA接收器的ID。在我的系统上,这是我得到的:
$ pactl list short sinks
0 alsa_output.pci-0000_01_00.1.hdmi-surround module-alsa-card.c s16le 6ch 44100Hz SUSPENDED
1 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
Sink 1 is currently my default sink.
But now I want all my current and future streams to be played via HDMI (i.e. sink 0).
There is a command to set the default sink for PulseAudio, but it doesn't seem to have any effect on my PC:
$ pacmd set-default-sink 0 #doesn't work on my PC :(
Instead, new streams seem to be connected to the sink that had a stream moved to it most recently.
So let's tell pactl to move all currently playing streams to sink 0
. We'll first need to list them:
$ pactl list short sink-inputs
290 1 176 protocol-native.c float32le 2ch 44100Hz
295 1 195 protocol-native.c float32le 2ch 44100Hz
Ok, we've got two streams (IDs 290 and 295) that are both attached to sink 1
.
Let's move them to sink 0
:
$ pactl move-sink-input 290 0
$ pactl move-sink-input 295 0
So, that should be it. Now we just have to make a script that does the work for us:
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <sinkId/sinkName>" >&2
echo "Valid sinks:" >&2
pactl list short sinks >&2
exit 1
fi
newSink="$1"
pactl list short sink-inputs|while read stream; do
streamId=$(echo $stream|cut '-d ' -f1)
echo "moving stream $streamId"
pactl move-sink-input "$streamId" "$newSink"
done
You can call it with either a sink ID or a sink name as parameter (i.e. either 0
or something like alsa_output.pci-0000_01_00.1.hdmi-surround
).
Now you could attach this script to a udev event or key shortcut.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句