Raspberry PI 聲音控制

指令

  • amixer
amixer controls
amixer cget numid=3
amixer cset numid=3 50%
amixer cset numid=3 50%,100%   // 左聲道 50% 右聲道 100%
amixer cset numid=4 off        // 靜音

vi /etc/init.d/alsa-utils  主要用來控制 ALSA script
vi /var/lib/alsa/asound.state   // ALSA 資料儲存地方

執行完下列動作後:

$ amixer cset numid=3 100%
numid=3,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw------,values=2,min=0,max=65536,step=1
  : values=65536,65536
$ amixer cset numid=4 on
numid=4,iface=MIXER,name='Master Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on
$ sudo alsactl store

/var/lib/alsa/asound.state 會被儲存為:

state.ALSA {
        control.1 {
                iface MIXER
                name 'PCM Playback Volume'
                value 399
                comment {
                        access 'read write'
                        type INTEGER
                        count 1
                        range '-10239 - 400'
                        dbmin -9999999
                        dbmax 400
                        dbvalue.0 399
                }
        }
        control.2 {
                iface MIXER
                name 'PCM Playback Switch'
                value true
                comment {
                        access 'read write'
                        type BOOLEAN
                        count 1
                }
        }
        control.3 {
                iface MIXER
                name 'PCM Playback Route'
                value 2
                comment {
                        access 'read write'
                        type INTEGER
                        count 1
                        range '0 - 2'
                }
        }
}

  • alsamixer 圖形化控制聲音工具
  • alsactl
  • aplay
aplay /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav
aplay /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav -v -V mono
aplay -l
  • speaker-test

重新載入工具程式

sudo /etc/init.d/alsa-utils reset

參考資料