Command-Line

Raspbian:檢查聲音輸出

  • January 23, 2020

如何從命令行檢查(使用 ALSA 外掛創建的虛擬設備的)音頻線路輸出是否有音頻信號?並檢查信號強度?

我找到了使用“sox”工具(sox man)的解決方案。我可以使用此答案中提出的方法(將聲音輸出發送到應用程序和揚聲器)在 alsa 虛擬設備呼叫“Loopback”中獲取信號,同時它也發送到輸出設備,然後使用 sox 查找是否有信號它的力量:

sox -b 16 -t alsa hw:Loopback,1,0 -r 48000 -n stat

(-b -> 16 位信號,-t (alsa hw:Loopback,1,0) -> 給我信號的虛擬設備,-r 48000 -> 採樣頻率和 -n stat -> 分析信號)

此命令給出如下輸出:

Input File     : 'hw:Loopback,1,0' (alsa)
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Sample Encoding: 16-bit Signed Integer PCM


In:0.00% 00:00:02.47 [00:00:00.00] Out:115k  [-=====|=====-] Hd:3.9 Clip:0  

Samples read:            229376
Length (seconds):      2.389333
Scaled by:         2147483647.0
Maximum amplitude:     0.630951
Minimum amplitude:    -0.630981
Midline amplitude:    -0.000015
Mean    norm:          0.159916
Mean    amplitude:    -0.004383
RMS     amplitude:     0.198459
Maximum delta:         1.176422
Minimum delta:         0.000000
Mean    delta:         0.223984
RMS     delta:         0.278537
Rough   frequency:        10721
Volume adjustment:        1.585

當你收到信號時,當沒有信號時:

Input File     : 'hw:Loopback,1,0' (alsa)
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Sample Encoding: 16-bit Signed Integer PCM

In:0.00% 00:02:23.70 [00:00:00.00] Out:6.89M [      |      ]        Clip:0

Samples read:          13787136
Length (seconds):    143.616000
Scaled by:         2147483647.0
Maximum amplitude:     0.000000
Minimum amplitude:     0.000000
Midline amplitude:     0.000000
Mean    norm:          0.000000
Mean    amplitude:     0.000000
RMS     amplitude:     0.000000
Maximum delta:         0.000000
Minimum delta:         0.000000
Mean    delta:         0.000000
RMS     delta:         0.000000
Rough   frequency:            0

“-n stat”工具的含義可以在(Sox 手冊頁)找到

引用自:https://unix.stackexchange.com/questions/563398