简体   繁体   中英

Get duration of .wav from sox in python

I know how to print the duration of the .wav file using sox at the Linux command.

soxi -D input.wav

So I used this syntax in python.

subprocess.call(['soxi', '-D', input.wav])

But I'd like to save the duration(seconds) in a variable. How do I get it in a variable?

+++++++++++ edit ++++++++++++++

using)

wavduration = subprocess.call(['soxi', '-D', input.wav])
print(wavduration)

output)

4.000000
0

This is not the right way to do it...

Python has sox wrapper and it has following method.

seconds = sox.file_info.duration('input file name')
print(seconds)

docs https://pysox.readthedocs.io/en/latest/api.html#module-sox.file_info

pysox https://github.com/rabitt/pysox/blob/master/README.md

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM