From aabb7c9fb9d18b12ba14b0e668f0a7aeac86f6c1 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Fri, 14 Mar 2014 17:34:30 +0000 Subject: [PATCH] Updated audio converter to use sox --- core/utils/waveform.py | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/core/utils/waveform.py b/core/utils/waveform.py index b0c098f..74d3a43 100755 --- a/core/utils/waveform.py +++ b/core/utils/waveform.py @@ -6,43 +6,23 @@ from dss import settings def generate_waveform(input_file, output_file): - working_file = "%s%s.png" % (settings.DSS_TEMP_PATH, uuid.uuid1()) try: print "Starting decode : %s\n\tIn: %s\n\tOut: %s" % \ - (settings.DSS_LAME_PATH, input_file, working_file) + (settings.DSS_LAME_PATH, input_file, output_file) #sox f679a81a-ea14-4385-a677-c663559d1e4b.mp3 -c 1 -t wav - #| /srv/dss/bin/wav2png -w 800 -h 120 -o song.png /dev/stdin - convert_command = "%s %s -c 1 -t wav -" % (settings.DSS_LAME_PATH, input_file) + convert_command = "%s %s -c 1 -t wav - | %s -w 800 -h 120 -o %s /dev/stdin" % \ + (settings.DSS_LAME_PATH, input_file, settings.DSS_WAVE_PATH, output_file) print "Convert command: %s" % convert_command - command_split = convert_command.split() - convert = subprocess.Popen(command_split, - stdout=subprocess.PIPE) + result = os.system(convert_command) + print result - waveform_command = "%s -w 800 -h 120 -o %s" % (settings.DSS_WAVE_PATH, working_file) - waveform = subprocess.Popen(waveform_command, - stdin=convert.stdout, stdout=subprocess.PIPE) - - convert.stdout.close() - output = waveform.communicate()[0] - - print "Finished decode\n%s" % output - - if os.path.exists(working_file): - print "Starting waveform generation" - ret = subprocess.call([ - settings.DSS_WAVE_PATH, "-w", "800", "-h", "120", "-o", - output_file, - working_file], stderr=subprocess.PIPE, stdout=subprocess.PIPE) - if os.path.isfile(output_file): - os.remove(working_file) - print "Generated waveform" - return output_file - else: - print "Failed generating waveform: %s" % output_file - print "Subprocess returned: %s" % ret + if os.path.exists(output_file): + return output_file else: print "Unable to find working file, did LAME succeed?" return "" + except Exception, ex: print "Error generating waveform %s" % (ex)