0

I'm actually using using a command line tool called sox to retrieve information about an audio file. This returns the following output:

Samples read:            449718
Length (seconds):     28.107375
Scaled by:         2147483647.0
Maximum amplitude:     0.999969
Minimum amplitude:    -0.999969
Midline amplitude:     0.000000
Mean    norm:          0.145530
Mean    amplitude:     0.000291
RMS     amplitude:     0.249847
Maximum delta:         1.316925
Minimum delta:         0.000000
Mean    delta:         0.033336
RMS     delta:         0.064767
Rough   frequency:          660
Volume adjustment:        1.000

I'd like to extract the values out of this using a regular expression. So far I have /^Length \(seconds\):\s*[0-9.]*/m which matches Length (seconds): 28.107375 but I just want the value.

What do I need to do?

4

3 回答 3

1

"soxi -D filename" 以秒为单位返回文件名的长度。只是数字,没有别的。关于 SoXI 的信息可以在这里找到

于 2012-08-24T10:57:06.260 回答
1

两种选择(我对 sox 不熟悉,所以我不确定这在 sox 中究竟是如何工作的):

  1. 您可以使用lookbehind 来匹配第一部分。这适用于正则表达式引擎允许可变长度后视的情况:/(?<=^Length \(seconds\)\:\s*)[\d.]*/
  2. 您可以捕获组中的值以供以后引用:/^Length \(seconds\):\s*([\d.]*)/. 如果 sox 具有捕获组功能,这将起作用。在这种情况下,该值将保存在第一个捕获组中(1 美元的红宝石)
于 2012-08-02T11:43:43.877 回答
0
awk '/^Length \(seconds\):/ { print $NF }'
于 2012-08-02T11:55:51.143 回答