standardise program/sox.py formatting, add test case, docstring (#53)
* standardise program/sox.py formatting, add test case
* add program/sox.peak_level() docstring
* update .travis.yml to include sox as a test dependency
* move sox from test dependency to normal dependency
* update README to mention sox, remove small autoconf mention
* use .splitlines() instead of .split('n')
This commit is contained in:
committed by
JoeLametta
parent
566414c939
commit
8721ba1caf
@@ -1,16 +1,24 @@
|
||||
import os
|
||||
import logging
|
||||
import os
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
SOX = 'sox'
|
||||
|
||||
def peak_level(track_path):
|
||||
if not os.path.exists(track_path):
|
||||
logging.warning("SoX peak detection failed: file not found")
|
||||
return None
|
||||
sox = Popen([SOX, track_path, "-n", "stat"], stderr=PIPE)
|
||||
out, err = sox.communicate()
|
||||
if sox.returncode:
|
||||
logging.warning("SoX peak detection failed: " + s.returncode)
|
||||
return None
|
||||
return float(err.split('\n')[3].split()[2]) # Maximum amplitude: 0.123456
|
||||
"""
|
||||
Accepts a path to a sox-decodable audio file.
|
||||
|
||||
Returns track peak level from sox ('maximum amplitude') as a float.
|
||||
Returns None on error.
|
||||
"""
|
||||
if not os.path.exists(track_path):
|
||||
logging.warning("SoX peak detection failed: file not found")
|
||||
return None
|
||||
sox = Popen([SOX, track_path, "-n", "stat"], stderr=PIPE)
|
||||
out, err = sox.communicate()
|
||||
if sox.returncode:
|
||||
logging.warning("SoX peak detection failed: " + str(sox.returncode))
|
||||
return None
|
||||
# relevant captured line looks like:
|
||||
# Maximum amplitude: 0.123456
|
||||
return float(err.splitlines()[3].split()[2])
|
||||
|
||||
Reference in New Issue
Block a user