Get Mean amplitude(only) of .wav from sox

那年仲夏 提交于 2019-12-24 03:17:55

问题


C:\Program Files\sox-14-4-0>sox Sample.wav -n stat

The above code gives below result

Samples read:             26640
Length (seconds):      3.330000
Scaled by:         2147483647.0
Maximum amplitude:     0.515625
Minimum amplitude:    -0.734375
Midline amplitude:    -0.109375
Mean    norm:          0.058691
Mean    amplitude:     0.000122
RMS     amplitude:     0.101146
Maximum delta:         0.550781
Minimum delta:         0.000000
Mean    delta:         0.021387
RMS     delta:         0.041831
Rough   frequency:          526
Volume adjustment:        1.362

Now i need only Mean amplitude. How to do that?


回答1:


There are a few ways.

Method 1:

"C:\Program Files\sox-14-4-0\sox" Sample.wav -n stat | find "Mean    amplitude: " > %TMP%\amp.tmp
set /p meanAMP=<%TMP%\amp.tmp
set meanAMP=%meanAMP:*:     =%
del %TMP%\amp.tmp
echo %meanAMP%

Method 2:

for /f "tokens=1-3" %%x in ('"%ProgramFiles%\sox-14-4-0\sox" Sample.wav -n stat') do (
  if "%%x %%y"=="Mean amplitude:" set meanAMP=%%z
)
echo %meanAMP%

Fastest:

Method 3:

for /f "skip=7 tokens=1-3" %%x in ('"%ProgramFiles%\sox-14-4-0\sox" Sample.wav -n stat') do (
  if "%%x %%y"=="Mean amplitude:" set meanAMP=%%z
)
echo %meanAMP%

Method 4:

for /f "tokens=1-3" %%x in ('"%ProgramFiles%\sox-14-4-0\sox" Sample.wav -n stat ^| find "Mean    amplitude:"') do (
  set meanAMP=%%z
)
echo %meanAMP%

I suspect that method 3 will be the fastest because:

Method 1 uses a lot of steps, including the external program find, the creation, access and deletion of a temporary file, and the redefinition of a variable.

Method 2 examines all the output of SOX.

Method 4 uses the external program find which slows down execution.

Method 3 actually skips the first 7 lines of output from SOX and THEN begins to evaluate the output.

NOTE: Methods 2-4 can all be done on a single line, just remove the ( and ).

EDIT: Fixed some errors in the code.

NOTE: To use from the command prompt Method 1 should work as-is. Methods 2-4 require changing all %%'s to %'s.

For example, you can paste this directly into cmd:

for /f "skip=7 tokens=1-3" %%x in ('"%ProgramFiles%\sox-14-4-0\sox" Sample.wav -n stat') do (
  if "%x %y"=="Mean amplitude:" set meanAMP=%z
)
echo %meanAMP%

Notice that this is almost an exact copy of method 3, except I changed %%x, %%y and %%z into %x, %y and %z respectively.



来源:https://stackoverflow.com/questions/12383496/get-mean-amplitudeonly-of-wav-from-sox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!