AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 26068
Accepted
myusuf3
myusuf3
Asked: 2011-02-13 18:44:26 +0800 CST2011-02-13 18:44:26 +0800 CST 2011-02-13 18:44:26 +0800 CST

你如何从命令行静音?

  • 772

如何从命令行静音声音系统?

command-line
  • 6 6 个回答
  • 83509 Views

6 个回答

  • Voted
  1. Best Answer
    goric
    2011-02-13T19:25:46+08:002011-02-13T19:25:46+08:00

    假设您正在使用 ALSA 驱动程序,请运行:

    amixer set Master mute   
    amixer set Master unmute
    

    或者,您可以只使用:

    amixer set Master toggle
    

    打开和关闭静音。

    • 86
  2. Tim
    2014-04-07T11:40:29+08:002014-04-07T11:40:29+08:00

    当其他人没有时,这对我有用:

    amixer -q -D pulse sset Master toggle
    

    这是来自关于 natty对第一个答案的评论的 nutty 链接:

    • 60
  3. Niko Riitala
    2014-01-13T00:35:24+08:002014-01-13T00:35:24+08:00

    我pactl在我的脚本中使用。从手册页:

    set-sink-mute SINK 1|0|toggle:设置指定sink的静音状态(由其符号名或数字索引标识)

    静音:

    pactl set-sink-mute @DEFAULT_SINK@ true
    

    取消静音:

    pactl set-sink-mute @DEFAULT_SINK@ false
    

    切换:

    pactl set-sink-mute @DEFAULT_SINK@ toggle
    

    使用0而不是@DEFAULT_SINK@设置具有数字索引 0 的接收器。true=="1", false=="0"。

    在 Ubuntu 12.10 上测试。
    在我的设置中,有时 amixer 取消静音由于某种原因会失败。

    • 39
  4. theTuxRacer
    2011-02-13T19:26:30+08:002011-02-13T19:26:30+08:00

    在终端上输入此静音

    amixer set Master mute
    

    类型

    amixer set Master unmute
    

    在我的 Ubuntu 10.10 上测试。

    • 17
  5. ton
    2019-08-05T12:30:49+08:002019-08-05T12:30:49+08:00

    如果您使用alsa跟随 goric 答案。

    PulseAudio 更好,但不是那么简单:pactl set-sink-mute 0 1为第一个设备执行工作,但如果您使用的是另一个接收器输出的耳机,则不是。

    更好的方法是检查pactl info并Default Sink使用。

    DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)
    

    然后静音:

    pactl set-sink-mute "$DEFAULT_SINK" "1"
    

    或取消静音:

    pactl set-sink-mute "$DEFAULT_SINK" "0"
    

    我在笔记中写了一个脚本来管理pulseaudio。如果要使用,将其另存为volume,提供执行权限chmod +x volume并将其添加到您的路径ln -sv $PWD/volume /usr/local/bin/中。这是我的脚本:

    #!/bin/bash
    # script name: volume
    # Author: glaudistong at gmail.com
    # depends on: yad, coreutils, pulseaudio
    
    ps -ef | grep "yad" | grep -E "Volume [^+\-]" | tr -s " " | cut -d " " -f2 | xargs -i kill "{}" 2>/dev/null
    DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)
    DEFAULT_SOURCE=$(pactl info | grep "Default Source" | cut -d " " -f3)
    case "$1" in 
        init)
        {
            ps -fe | grep yad | grep -q volume ||
            {
             yad --notification --command "volume up" --text "+ Volume +" --image ~/Pictures/volume-up-dark.png &
             yad --notification --command "volume down" --text "- Volume -" --image ~/Pictures/volume-down-dark.png &
            }
        };;
        up)
        {
            pactl set-sink-volume "$DEFAULT_SINK" +5%
            P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
            iconl="$(echo -ne "\U1F50A")"
            iconr="$(echo -ne "\U1F56A")"
            timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
        };;
        down)
        {
            pactl set-sink-volume "$DEFAULT_SINK" -5%
            P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
            iconl="$(echo -ne "\U1F509")"
            iconr="$(echo -ne "\U1F569")"
            timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
        };;
        mute)
        {
            ismute=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
            if [ "$ismute" == no ]; then
                s=1
                P=0
                icon="$(echo -ne "\U1F507")"
            else
                P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
                icon="?"
                s=0
            fi
            pactl set-sink-mute "$DEFAULT_SINK" "$s"
            echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::mute/brightness
            timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume $P%" --no-focus --center --skip-taskbar --on-top &
        };;
        mic-up)
        {
            pactl set-source-volume "$DEFAULT_SOURCE" +5%
            P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
            icon="$(echo -en "\U1F3A4")"
            timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
        };;
        mic-down)
        {
            pactl set-source-volume "$DEFAULT_SOURCE" -5%
            icon="$(echo -en "\U1F3A4")"
            P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
            timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
        };;
        mic-mute)
        {
            ismute=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
            if [ "$ismute" == no ]; then
                s=1
                P=0
                icon="$(echo -en "\U1F507\U1F3A4")"
            else
                P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
                s=0
                icon="$(echo -en "\U1F3A4")"
            fi
            pactl set-source-mute "$DEFAULT_SOURCE" "$s"
            echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness
            timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
        };;
        *)
            echo invalid option;;
    esac;
    
    • 8
  6. bhanu pratap
    2021-05-30T01:33:05+08:002021-05-30T01:33:05+08:00

    如果您使用 pulseaudio 作为声音服务器,请执行此操作

    pactl -- set-sink-mute @DEFAULT_SINK@ toggle # Also true/false to mute/unmute
    

    静音和取消静音

    如果使用 alsa 然后使用这个

    amixer sset 'Master' toggle
    

    静音和取消静音

    • 2

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    我需要什么命令来解压缩/提取 .tar.gz 文件?

    • 8 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Martin Hope
    EmmyS 我需要什么命令来解压缩/提取 .tar.gz 文件? 2011-02-09 14:50:41 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve