#! /usr/bin/env python # Wrapper for the Matlab command "Wiener_iter_mel.m" # # By G. Lathoud 2006 - lathoud@idiap.ch import sys, os syntax_string = 'Usage: ' + sys.argv[0] + ' [-nv] [-m ] [-b ] [-s ] ' syntax_string = syntax_string + '\n -nv desactivates verbose mode (default: verbose)' syntax_string = syntax_string + '\n -m to specify the maximum amplitude of the output waveform (0 < new_M <= 1)' syntax_string = syntax_string + '\n -b to specify the block size, in seconds' syntax_string = syntax_string + '\n -s to specify the silence buffer size, in seconds (usually about half the blocksize)' syntax_string = syntax_string + '\n -i to specify the number of iterations (non-negative integer, e.g. 1 or 2)'; syntax_string = syntax_string + '\n' # Parse the input parameters inarg = sys.argv myname = inarg.pop( 0 ) if '-h' in inarg: print syntax_string sys.exit( 0 ) verbose = not ( '-nv' in inarg ) if not verbose: inarg.remove( '-nv' ) newmaxspecified = ( '-m' in inarg ) if newmaxspecified: index = 1 + inarg.index( '-m' ) if len( inarg ) <= index: print syntax_string sys.exit( 2 ) newmax = inarg[ index ] inarg.pop( index ) inarg.pop( index - 1 ) blocksizespecified = ( '-b' in inarg ) if blocksizespecified: index = 1 + inarg.index( '-b' ) if len( inarg ) <= index: print syntax_string sys.exit( 2 ) blocksize = inarg[ index ] inarg.pop( index ) inarg.pop( index - 1 ) silbufferspecified = ( '-s' in inarg ) if silbufferspecified: index = 1 + inarg.index( '-s' ) if len( inarg ) <= index: print syntax_string sys.exit( 2 ) silbuffer = inarg[ index ] inarg.pop( index ) inarg.pop( index - 1 ) niterspecified = ( '-i' in inarg ) if niterspecified: index = 1 + inarg.index( '-i' ) if len( inarg ) <= index: print syntax_string sys.exit( 2 ) niter = inarg[ index ] inarg.pop( index ) inarg.pop( index - 1 ) if len( inarg ) < 2: print syntax_string sys.exit( 2 ) input_filename = inarg[ 0 ] output_filename = inarg[ 1 ] # Verbosity if verbose: print myname + ': verbose mode.' if newmaxspecified: print myname + ': output maximum value = ' + newmax + '.' else: print myname + ': output maximum value not specified.' if blocksizespecified: print myname + ': block size = ' + blocksize + ' seconds.' else: print myname + ': block size not specified.' if silbufferspecified: print myname + ': silence buffer size = ' + silbuffer + ' seconds.' else: print myname + ': silence buffer size not specified.' if niterspecified: print myname + ': niter = ' + niter + '.' else: print myname + ': number of iterations not specified, using default value.' # Check that the input file is available if not os.path.exists( input_filename ): print myname + ' cannot find the input file "' + input_filename + '".' print myname + ' aborted.' sys.exit( 1 ) # Prepare the Matlab command matlab_command = 'par = [];' matlab_command = matlab_command + ' par.in_filename = \'' + input_filename + '\';' matlab_command = matlab_command + ' par.out_filename = \'' + output_filename + '\';' if newmaxspecified: matlab_command = matlab_command + ' par.new_M = ' + newmax + ';' if blocksizespecified: matlab_command = matlab_command + ' par.blocksize_sec = ' + blocksize + ';' if silbufferspecified: matlab_command = matlab_command + ' par.silbuffer_sec = ' + silbuffer + ';' if niterspecified: matlab_command = matlab_command + ' par.niter = ' + niter + ';' matlab_command = matlab_command + ' par.verbose = %d;' % verbose matlab_command = matlab_command + ' dbstop error;' # In case there is an error, this is useful to backtrack matlab_command = matlab_command + ' Wiener_iter_mel( par );' matlab_command = matlab_command + ' exit;' # Prepare the OS command os_command = 'matlab -nodisplay -nojvm -r "' + matlab_command + '"' if not verbose: os_command = os_command + ' >> /dev/null' # Launch it if verbose: print myname + ': calling Matlab...' print myname + ' (to interrupt, press ctrl+Z and type "kill %")' os.system( os_command )