gpt4 book ai didi

bash - 可以通过CLI在Linux中使音频静音的脚本有效,但需要帮助

转载 作者:行者123 更新时间:2023-12-03 01:36:59 24 4
gpt4 key购买 nike

我经常在工作时播放新闻,并想在广告期间使声音静音,因此四处张望,发现这个Stackoverflow thread产生了一些好处,并产生了以下脚本,其工作原理很像魅力:

#!/bin/bash
#Mute, wait, unmute: attempt 1
for x in `amixer controls | grep layback` ; do
amixer cset "${x}" on ; done
echo Mute for how many seconds?
read v1
sleep $v1
for x in `amixer controls | grep layback` ; do
amixer cset "${x}" 700% ; done

可以,但是会在终端屏幕上造成混乱:(只是一种味道)
<p>161 [~]$ MM<br>
numid=16,iface=MIXER,name='Master Playback Switch'<br>
; type=BOOLEAN,access=rw------,values=1<br>
: values=on<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
numid=15,iface=MIXER,name='Master Playback Volume'<br>
; type=INTEGER,access=rw---R--,values=1,min=0,max=127,step=0<br>
: values=0<br>
| dBscale-min=-95.25dB,step=0.75dB,mute=1<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>...etc</p>

在cset之后添加-q可以清理一点
<p>166 [~]$ MM<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
amixer: Control default element write error: Operation not
permitted<br>...etc</p>

但是,为什么我会收到所有这些“错误的控件标识符”消息?

我尝试使用 man grep,但随后我的头掉了下来,不得不重新贴上磁带,现在我头疼。而且我饿了。

干杯
奥姆尼

最佳答案

试试这个:

read -p "Mute for how many seconds? " v1 ; \
amixer controls | grep layback | grep -v ' Ma' |
xargs -I '{}' amixer -q cset '{}' on ; \
sleep $v1 ; \
amixer controls | grep layback | grep -v ' Ma' |
xargs -I '{}' amixer -q cset '{}' 700%

笔记:
  • 主要的麻烦似乎是诸如“Playback Con Mask”和
    “播放 channel map ”与amixer选项不兼容。使用grep -v过滤这些混音器可以解决该问题。
  • 应该首先使用read,否则静音将持续输入
    秒钟用户输入它们所花费的时间。
  • xargs在这里实际上不是必需的,但它似乎比使用简单
    有变量的循环。
  • 这些; \使得一键复制和粘贴到命令行更加容易。在脚本中,不需要; \行结尾。
  • 关于bash - 可以通过CLI在Linux中使音频静音的脚本有效,但需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51907279/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com