【问题标题】:How to allow pulse audio script to increase volume over 100% through bash [closed]如何允许脉冲音频脚本通过 bash 将音量增加 100% 以上 [关闭]
【发布时间】:2014-04-02 15:56:27
【问题描述】:

我是 using this script 来通过 keybindigs 更改 pulseaudio 的音量,但它有一个 0%100% 的限制。

由于 pulseaudio 允许音量增加到超过 100%(我的笔记本上的音量仍然很低),我想调整它以允许 140%150% 最大音量。

请注意,仅通过注释行 105 ~ 111 脚本可以正常工作,但没有限制值(什么会破坏我的扬声器)。我真正想要的是在100% 上设置一个可配置的限制。

实际上,这是一个bash 的问题,而不是pulseaudio

Gist with the complete script

【问题讨论】:

    标签: bash pulseaudio


    【解决方案1】:

    只需将 MAXVOL 增加到 100000 左右(其原始值的 150%,65537)。

    【讨论】:

    • 它不起作用。 MAXVOL 的任何高于65537 的值都会导致 VOLSTEP 超过 100%,并且在计算 VOLUME 时它会升高很多。这样音量很容易超过 200% 并且不能降低。
    【解决方案2】:

    我设法通过添加一个新变量和一些数学来改变它。

    OVERMAX 值(调整到所需的最大百分比)用于设置新的百分比值。所以130% 变成了100%

    #!/bin/sh
    #   pulsevol.sh
    #   PulseAudio Volume Control Script
    #   Original 2010-05-20 - Gary Hetzel <garyhetzel@gmail.com>
    #      
    #   Modified 2010-10-18 by Fisslefink <fisslefink@gmail.com>
    #    - Added support for multiple sinks and Ubuntu libnotify OSD
    #
    #   Usage:  pulsevol.sh [sink_index] [up|down|min|max|overmax|toggle|mute|unmute]
    #
    
    EXPECTED_ARGS=2
    E_BADARGS=65
    
    if [ $# -ne $EXPECTED_ARGS ]
    then
        echo "Usage: `basename $0` [sink_index] [up|down|min|max|overmax|toggle|mute|unmute]"
        exit $E_BADARGS
    fi
    
    SINK=$1
    STEP=5
    MAXVOL=65537 # let's just assume this is the same all over
    #MAXVOL=`pacmd list-sinks | grep "volume steps" | cut -d: -f2 | tr -d "[:space:]"`
    OVERMAX=130  # how much the volume can raise over 100%
    
    getperc(){
        VOLPERC=`pacmd list-sinks | grep "volume" | head -n1 | cut -d: -f3 | cut -d% -f1 | tr -d "[:space:]"`
    }
    
    getperc;
    
    up(){
        VOLSTEP="$(( $VOLPERC+$STEP ))";
    }
    
    down(){
        VOLSTEP="$(( $VOLPERC-$STEP ))";
    }
    
    max(){
        pacmd set-sink-volume $SINK $MAXVOL > /dev/null
    }
    
    min(){
        pacmd set-sink-volume $SINK 0 > /dev/null
    }
    
    overmax(){
        SKIPOVERCHECK=1
        if [ $VOLPERC -lt 100 ]; then
            max;
            exit 0;
        fi
        up
    }
    
    mute(){
        pacmd set-sink-mute $SINK 1 > /dev/null
        notify-send " " -i "notification-audio-volume-muted" -h int:value:0 -h string:synchronous:volume
    }
    
    unmute(){
        VOLSTEP="$(( $VOLPERC-0 ))";
        SKIPOVERCHECK=1
        pacmd set-sink-mute $SINK 0 > /dev/null
    }
    
    toggle(){
        M=`pacmd list-sinks | grep "muted" | cut -d: -f2 | tr -d "[:space:]"`
        if [ "$M" = "no" ]; then
            mute
            exit 0;
        else
            unmute;
        fi
    }
    
    case $2 in
    up)
        up;;
    down)
        down;;
    max)
        max
        exit 0;;
    min)
        min
        exit 0;;
    overmax)
        overmax;;
    toggle)
        toggle;;
    mute)
        mute;
        exit 0;;
    unmute)
        unmute;;
    *)
        echo "Usage: `basename $0` [sink_index] [up|down|min|max|overmax|toggle|mute|unmute]"
        exit 1;;
    esac
    
    VOLUME="$(( ($MAXVOL/100) * $VOLSTEP ))"
    MAXCHECK="$(( $MAXVOL * $OVERMAX / 100  ))"
    
    if [ -z $SKIPOVERCHECK ]; then
        if [ $VOLUME -gt $MAXCHECK ]; then
            VOLUME=$MAXCHECK
        elif [ $VOLUME -lt 0 ]; then
            VOLUME=0
        fi
    fi
    
    pacmd set-sink-volume $SINK $VOLUME > /dev/null
    
    VOLPERC=`pacmd list-sinks | grep "volume" | head -n1 | cut -d: -f3 | cut -d% -f1 | tr -d "[:space:]"`
    VOLPERC="$(( $VOLPERC * 100 / $OVERMAX))"
    
    if [ "$VOLPERC" = "0" ]; then
            icon_name="notification-audio-volume-off"
        else
            if [ "$VOLPERC" -lt "33" ]; then
                icon_name="notification-audio-volume-low"
            else
                if [ "$VOLPERC" -lt "67" ]; then
                    icon_name="notification-audio-volume-medium"
                else
                    icon_name="notification-audio-volume-high"
                fi
            fi
    fi
    
    notify-send " " -i $icon_name -h int:value:$VOLPERC -h string:synchronous:volume
    

    要点:https://gist.github.com/paulodiovani/67906a5bf0392de51eca

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-28
      • 2012-09-14
      • 1970-01-01
      • 2013-08-13
      • 2020-09-27
      • 2023-03-11
      • 2011-05-17
      • 1970-01-01
      相关资源
      最近更新 更多