从sox获取.wav的平均幅度(仅) [英] Get Mean amplitude(only) of .wav from sox

查看:654
本文介绍了从sox获取.wav的平均幅度(仅)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

上面的代码给出以下结果

 读取的样本:26640 
长度(秒):3.330000
缩放:2147483647.0
最大振幅:0.515625
最小振幅:-0.734375
中线幅度:-0.109375
平均范数:0.058691
平均振幅:0.000122
RMS振幅:0.101146
最大增量:0.550781
最小增量:0.000000
平均增量:0.021387
RMS增量:0.041831
粗糙频率:526
音量调整:1.362

现在我只需要平均幅度。




解决方案有几种方法。

>方法1:

 C:\Program Files \sox-14-4-0 \sox wav -n stat |找到平均幅度:> %TMP%\amp.tmp 
set / p meanAMP =<%TMP%\amp.tmp
set meanAMP =%meanAMP:*:=%
del%TMP% \\amp.tmp
echo%meanAMP%






方法2:

  for / ftokens = 1-3%% x在(''%ProgramFiles% \\sox-14-4-0 \soxSample.wav -n stat')do(
如果%% x %% y==平均幅度:set meanAMP = %% z

echo%meanAMP%






最快:



方法3:

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

echo%meanAMP%






方法4:

  tokens = 1-3%% x in('%ProgramFiles%\sox-14-4-0 \soxSample.wav -n stat ^ | findMean amplitude:')do(
set meanAMP = %% z

echo%meanAMP%

我怀疑方法3将是最快的,因为:



方法1使用很多步骤,包括外部程序 find

方法2检查 SOX的所有输出。



方法4使用外部程序 find ,这会减慢执行速度。方法3实际上跳过 SOX 的前7行输出,THEN开始计算输出。



注意:方法2-4可以在一行上完成,只需删除



EDIT:修复了代码中的一些错误。 >

注意:要从命令提示符使用,方法1应该按原样工作。方法2-4需要将所有 %% 更改为'。



例如,您可以将它直接粘贴到 cmd

 code> for / fskip = 7 tokens = 1-3%% x in(''%ProgramFiles%\sox-14-4-0\soxSample.wav -n stat')do (
if%x%y==Mean amplitude:set meanAMP =%z

echo%meanAMP%
注意这几乎是方法3的精确副本,除了我改变了 %% x ,<$> c $ c> %% y
%% z 变成%x ,<$分别为c $ c>%y 和%z


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?

解决方案

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.

这篇关于从sox获取.wav的平均幅度(仅)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆