如何以较小的增量进行音量变化?

当我按下键盘上的音量增大/减小键时,音量变化太大。 如何使步长变小,以便我有更好的控制?

11.10 / 12.04

从这个错误报告中可以看出,音量步骤键在11.10中消失了,并且还没有(现在)重新出现。

因此,您无法通过简单的直接配置更改来减少音量步长。

链接中的post#18提供了一个有趣的解决方法,包括使用alsamixer增量和减量function以及向桌面发送通知。

但是我无法让它工作 – 因此我对该解决方案的看法是基于该post。

使用此解决方案,默认卷步骤将减少到2%的步骤。


如何

安装xbindkeys包(使用Synaptic,或使用sudo apt-get install xbindkeys )。

使用您喜欢的文本编辑器,在您的主文件夹中创建一个名为.volumeHack.sh文件,并将下面的内容复制并粘贴到该文件中,即

 gedit ~/.volumeHack.sh 

运行chmod a+x .volumeHack.sh使其可执行。

然后编辑文件~/.xbindkeysrc并复制并粘贴此文件底部的文本。 即

 gedit ~/.xbindkeysrc 

注销并登录

.xbindkeysrc

 # Increase volume #"amixer set Master playback 1+" "sh ~/.volumeHack.sh -c up -i 2% -m Master" m:0x0 + c:123 XF86AudioRaiseVolume # Decrease volume "sh ~/.volumeHack.sh -c down -i 2% -m Master" m:0x0 + c:122 XF86AudioLowerVolume # Toggle mute - this is not used here #"amixer set Master toggle" # m:0x0 + c:121 # XF86AudioMute 

.volumeHack.sh

 #!/bin/sh usage="usage: $0 -c {up|down|mute} [-i increment] [-m mixer]" command= increment=5% mixer=Master while getopts c:i:m:ho do case "$o" in c) command=$OPTARG;; i) increment=$OPTARG;; m) mixer=$OPTARG;; h) echo "$usage"; exit 0;; ?) echo "$usage"; exit 0;; esac done #echo "command:$command" #echo "increment:$increment" #echo "mixer:$mixer" if [ "$command" = "" ]; then shift $(($OPTIND - 1)) command=$1 exit 0; fi if [ "$command" = "" ]; then echo "usage: $0 {up|down|mute} [increment]" exit 0; fi display_volume=0 if [ "$command" = "up" ]; then display_volume=$(amixer set $mixer $increment+ unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1) fi if [ "$command" = "down" ]; then display_volume=$(amixer set $mixer $increment- unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1) fi icon_name="" if [ "$command" = "mute" ]; then if amixer get Master | grep "\[on\]"; then display_volume=0 icon_name="notification-audio-volume-muted" amixer set $mixer mute else display_volume=$(amixer set $mixer unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1) fi fi if [ "$icon_name" = "" ]; then if [ "$display_volume" = "0" ]; then icon_name="notification-audio-volume-off" else if [ "$display_volume" -lt "33" ]; then icon_name="notification-audio-volume-low" else if [ "$display_volume" -lt "67" ]; then icon_name="notification-audio-volume-medium" else icon_name="notification-audio-volume-high" fi fi fi fi notify-send " " -i $icon_name -h int:value:$display_volume -h string:synchronous:volume #echo "icon: $icon_name and $display_volume" 

Ubuntu 14.04 / 15.04 / 15.10 / 16.04 / 16.10 / 17.04

我终于为Trusty,Vivid,Wily,Xenial,Yakkety和Zesty用户提供了一个合适的解决方案。 我决定在源代码中修复问题,而不是使用一堆黑客或脚本。 我将此补丁应用于gnome-settings-daemon 安装gnome-settings-daemon 和unity-settings-daemon 安装unity-settings-daemon (对补丁进行了一些微不足道的修改)。

我已将包上传到PPA:

PPA:乔治edison55 / GNOME的设置守护 Launchpad徽标 ( 单击此处获取有关使用PPA的说明。 )

添加PPA后,运行:

 sudo apt-get update sudo apt-get upgrade 

安装完成后需要重新启动。 升级包后,可以使用dconf命令 Manpage图标 更改音量增量:

 dconf write /org/gnome/settings-daemon/plugins/sound/volume-step 2 

(默认值为6.)

现在按下音量键时,音量将以2为增量变化:

在此处输入图像描述

10.04 / 10.10 / 11.04

我刚刚发现gconf-editor的设置为“Volume step as volume of volume”:

/apps/gnome_settings_daemon/volume_step

更优雅,它适用于OSD音量通知。

这个简单的解决方案适用于(至少)12.04并且不需要CCSM。

使用键盘快捷键时,您不会有屏幕上的音量条操作,但是您可以根据需要进行细粒度音量控制。

  1. 系统设置>键盘>“快捷方式”选项卡>“声音和媒体”类别

  2. 禁用现有的“降低音量”和“音量调高”快捷键。 要执行此操作,请在每次单击以选中它,然后按退格键以清除与其关联的任何键组合。

  3. 现在选择“自定义快捷方式”类别,然后单击“+”图标以创建两个新快捷方式,如下所示:

     名称:音量增大 
    命令:amixer设为Master 3%+
     名称:降低音量 
    命令:amixer设为Master 3% -

    (试验百分比。如果你需要非常精细,那么省略%符号,它将使用0-255比例而不是百分比)。

  4. 现在将每个新快捷方式分配给一个键或键组合:选择一个快捷方式,然后在键盘上键入所需的一个或多个键。

在此之后,当您使用键盘音量控件时,您应该具有指定的任何音量增量。 您始终可以通过禁用自定义快捷方式并在“声音和媒体”类别中重新启用预制快捷方式来恢复原始行为。

您可以使用CompizConfig设置管理器执行此操作。 如果尚未安装,请使用命令sudo apt-get install compizconfig-settings-manager

现在打开CompizConfig设置管理器并转到“ 常规”部分中的“ 命令 ”。 选中右侧的“ 启用命令”复选框。 在“ 命令”选项卡中,分别输入以下两个命令作为两个命令:

amixer set Master 5%+ -q

amixer set Master 5%- -q

为“ 键绑定”选项卡中的命令分配两个键盘快捷 。 我使用Super + [和Super +]组合。 现在关闭CompizConfig设置管理器,这应该工作。

我不确定您是否可以将命令分配给计算机的内置音量控制器。

12.04(可能是11.10)

如果要直接控制pulseaudio音量而不是ALSA路径,可以使用以下脚本。 虽然也应该可以通过DBUS来控制音量,详见Stackoverflow的答案 ,但是我找不到在Ubuntu 12.04中使用它的方法。

正如脚本本身所说,它使用这个Stackoverflow答案来解决如何以编程方式更改Ubuntu中的卷并将该想法扩展为一个脚本,该脚本将卷更改作为命令行参数并显示OSD通知。 我试图尽可能地将其建模为默认的Ubuntu(12.04)行为。

该脚本将卷更改作为绝对或相对数字或百分比值。 例如:

  • pavol.sh 2000将卷设置为2000,
  • pavol.sh 30%将音量设置为30%,
  • pavol.sh +1000将音量增加1000和
  • pavol.sh -5%将音量降低5%。

它也非常自由地评论,希望它有助于进一步调整。

如何

使用您喜欢的文本编辑器在您的主文件夹(或其他任何地方 – 只记得路径)中创建一个名为pavol.sh文件,并将下面的内容复制并粘贴到该文件中,即

 gedit ~/pavol.sh 

运行chmod a+x ~/pavol.sh使其可执行。

然后打开Sytem Settings ,转到Keyboard设置并切换到Shortcuts选项卡。 单击Custom Shortcuts并使用加号按钮创建两个新的键盘快捷方式。

给每个人一个名字,并输入如下命令: /home/username/pavol.sh "+3%"输入pavol.sh脚本的完整路径很重要(除非脚本位于一个文件夹中包含在PATH环境变量中)。 同时在音量值周围使用引号""或键盘快捷键不起作用。

然后单击每个条目的右侧以设置组合键或多媒体键。 如果已将所需的组合或键分配给另一个快捷方式,程序将询问您是否要重新分配该快捷方式。

pavol.sh

 #!/bin/bash -- ## This script expands upon this answer on stackoverflow: ## https://stackoverflow.com/a/10739764 ## ## GLOBAL VARIABLES # restrict usable commands PATH="/bin:/usr/bin" # this script changes the volume of the default sink (as set, for instance, via the Ubuntu sound menu); # use "pactl info" to display these settings neatly in a terminal DEFAULT_SINK=$(pacmd dump | grep 'set-default-sink' | cut -d ' ' -f 2) # get max. volume from the DEFAULT_SINK MAX_VOL=$(pacmd list-sinks | grep -A 20 "name: <${DEFAULT_SINK}>" | grep "volume steps:" | tr -d '[:space:]' | cut -d ':' -f 2) # show debug messages? # 0 means no debug messages; 1 prints the current volume to the console at the end of the script; 2 switches on bash debugging via "set -x" DEBUG=0 ## FUNCTIONS # generate trace output if DEBUG is 2 or higher if [ ${DEBUG} -gt 1 ]; then set -x; fi # use poor man's return buffer via this variable (This is not stackable!) RETVAL="" # print simple usage text to console show_usage() { echo "Usage: $(basename ${0}) [+|-][number|percentage]" } # return (via RETVAL) the current pulseaudio volume as hexadecimal value get_cur_vol() { RETVAL=$(pacmd dump | grep "set-sink-volume ${DEFAULT_SINK}" | cut -d ' ' -f 3) } # change the pulseaudio volume as set in the first parameter variable, ie ${1}; # this can either be an absolute percentage or normal value, for instance 20% or 2000, # or a relative percentage or normal value, for instance +3% or -5% or +200 or -1000 change_vol() { step=${1} relative=${step:0:1} # extract first character percent=${step: -1} # extract last character # cut off first character for easier calculations, if it is either a "+" or "-" if [ "${relative}" = "+" -o "${relative}" = "-" ]; then step=${step:1}; fi # if the last character of ${step} was, in fact, a percent sign... if [ "${percent}" = "%" ]; then step=${step:0:-1} # cut off last character for easier calculations step=$[step*MAX_VOL/100] # change percentage into fixed value via MAX_VOL fi # save current volume in ${old_vol} get_cur_vol old_vol=$[RETVAL+0] # the dummy calculation turns the hexadecimal number to a decimal one # calculate the new volume value ${new_vol} with the operand that was extracted earlier if [ "${relative}" = "+" ]; then new_vol=$[old_vol+step] else if [ "${relative}" = "-" ]; then new_vol=$[old_vol-step] else # no operand found, so ${step} must be an absolute value new_vol=${step} fi fi # check boundaries - don't go below 0 and above MAX_VOL if [ ${new_vol} -lt 0 ]; then new_vol=0; fi if [ ${new_vol} -gt ${MAX_VOL} ]; then new_vol=${MAX_VOL}; fi # set the new volume pactl -- set-sink-volume "${DEFAULT_SINK}" "${new_vol}" # mute the sink if the new volume drops to 0 ... if [ ${new_vol} -le 0 ]; then pactl -- set-sink-mute "${DEFAULT_SINK}" yes else # ... or unmute the sink if the new volume is greater than the old if [ ${new_vol} -gt ${old_vol} ]; then pactl -- set-sink-mute "${DEFAULT_SINK}" no fi fi } # show an OSD notification notify_osd() { # get current volume get_cur_vol cur_vol_percent=$[RETVAL*100/MAX_VOL] # get mute state (gives "yes" or "no") muted=$(pacmd dump | grep "set-sink-mute ${DEFAULT_SINK}" | cut -d ' ' -f 3) # choose suitable icon (modeled after the default Ubuntu 12.04 behavior): # muted-icon if volume is muted if [ "${muted}" = "yes" ]; then icon="notification-audio-volume-muted" else # icon with loudspeaker and 1 of the 3 circle segments filled if volume is less than 34% if [ ${cur_vol_percent} -lt 34 ]; then icon="notification-audio-volume-low" else # icon with loudspeaker and 2 of the 3 circle segments filled if volume is between 34% and 66% if [ ${cur_vol_percent} -lt 67 ]; then icon="notification-audio-volume-medium" else # icon with loudspeaker and all 3 of the 3 circle segments filled if volume is higher than 66% icon="notification-audio-volume-high" fi fi fi # show notification notify-send "Volume" -i ${icon} -h int:value:${cur_vol_percent} -h string:synchronous:volume } # fake main function, that gets called first and kicks off all the other functions main() { # only change volume if input is a number with either a +/- prefix and/or a % suffix if [[ "${1}" =~ ^[+-]?[0-9]+[%]?$ ]]; then change_vol ${1} else show_usage fi # show volume osd notify_osd # show the new - now current - volume in hexadecimal, decimal and percentage if DEBUG is greater than 0 if [ ${DEBUG} -gt 0 ]; then get_cur_vol echo "${RETVAL} - $[RETVAL+0] - $[RETVAL*100/MAX_VOL]%" fi } ## REAL MAIN # run the fake main function and pass on all command line arguments; then exit the script main ${@} exit 0 

值得注意的是,在Ubuntu 17.10上,已经(尽管有点复杂)对此有所支持。 按Shift + XF86AudioRaiseVolume (或XF86AudioLowerVolume )以较小的步长更改音量。

在此处输入图像描述

Kubuntu 17.04

编辑通常位于以下位置的文件main.xml/usr/share/plasma/plasmoids/org.kde.plasma.volume/contents/config/main.xml

查找volumeStep条目:

  2  

并将每步的百分比更改为您想要的任何值。 你可以看到我使用2%。

正如Kubuntu 16.04所写,您需要重新启动Plasma才能使其生效:

 killall plasmashell #to stop it kstart plasmashell #to restart it 

Kubuntu 16.04

我从14.04升级,它具有主音量级别以及各个输入源和输出源,以及3%的递增/递减步骤(后来改为5%)。 通过简单地调整输出源音量水平来补偿主音量步长,我设法将其保持在2%和3%左右的步长。

很自然地,当16.04将此值提高到6%时,我有点恼火,并取消了主音量控制,而音量按钮控制了两个输出源。

Ubuntu 16.04的上述修复程序不适用于KDE5上使用的Plasma 5接口,因此不适用于Kubuntu 16.04 – 我尝试过,但它不起作用。

所以,我在网上做了一个快速检查,这个过程需要手动更改文件,但它相当简单。

编辑通常位于/usr/share/plasma/plasmoids/org.kde.plasma.volume/contents/ui/ListItemBase.qml的文件ListItemBase.qml

函数increaseVolumedecreaseVolume中有几行,它们通过将最大音量除以15来定义步骤。它们看起来像:

 var step = slider.maximumValue / 15; 

数字越大,步骤越小。 如果这是1,则体积为0%或100%,但如果为100,则体积将以1%的步长增加。

就个人而言,我的目标是2%,所以我将这两行改为

 var step = slider.maximumValue / 50; 

归功于此Reddit: https : //www.reddit.com/r/kde/comments/3t1xr0/how_to_change_the_volume_increment_step_size_for/

但是,您需要重新启动Plasma才能使其生效:

 killall plasmashell #to stop it kstart plasmashell #to restart it 

希望这可以帮助某人,甚至可能导致有人提交等离子的改变以使这个配置驱动…两个可能最终成为我在另一次更新后。