如何通过终端在两个音频输出之间切换?

我有两个音频输出:一个是无线耳机,另一个是我的笔记本电脑的内置3.5毫米插孔。 如何通过终端在它们之间切换? 最终,我想指定一个键盘快捷键来进行切换。

我构建了一个执行切换的脚本 。 我用xbindkeys调用它。 我确信它可以改进,因为我对grep不是很好,并且脚本在数字而不是名字的基础上工作并不理想。 脚本很大,因为自动化过程需要花费很多精力,但以下是必不可少的部分:

 # Identify any active sink inputs (audio streams - identified by number). pacmd list-sink-inputs # Identify the next sink (output - identified by number or by name). pacmd list-sinks # Switch the sink input to the next sink. pactl move-sink-input "$sink_input" "$next_sink" # Change the default sink to the next one. pactl set-default-sink "$next_sink"