def generate_test_files(src, dest, nseconds, fmts=['.mp3', '.wav'], padding=10):
 for directory in [src, dest]:
  try:
   os.stat(directory)
  except:
   os.mkdir(directory)
 for fmt in fmts:
  testsources = get_files_recursive(src, fmt)
  for audiosource in testsources:
   print 'audiosource:', audiosource
   (filename, extension) = os.path.splitext(os.path.basename(audiosource))
   length = get_length_audio(audiosource, extension)
   starttime = get_starttime(length, nseconds, padding)
   test_file_name = ('%s_%s_%ssec.%s' % (os.path.join(dest, filename), starttime, nseconds, extension.replace('.', '')))
   subprocess.check_output(['ffmpeg', '-y', '-ss', ('%d' % starttime), '-t', ('%d' % nseconds), '-i', audiosource, test_file_name])

def generate_test_files ( src , dest , nseconds , fmts = [ '.mp3' , '.wav' ] , padding = 10 ) : for directory in [ src , dest ] : try : os . stat ( directory ) except : os . mkdir ( directory ) for fmt in fmts : testsources = get_files_recursive ( src , fmt ) for audiosource in testsources : print 'audiosource:' , audiosource ( filename , extension ) = os . path . splitext ( os . path . basename ( audiosource ) ) length = get_length_audio ( audiosource , extension ) starttime = get_starttime ( length , nseconds , padding ) test_file_name = ( '%s_%s_%ssec.%s' % ( os . path . join ( dest , filename ) , starttime , nseconds , extension . replace ( '.' , '' ) ) ) subprocess . check_output ( [ 'ffmpeg' , '-y' , '-ss' , ( '%d' % starttime ) , '-t' , ( '%d' % nseconds ) , '-i' , audiosource , test_file_name ] )
generates a test file for each file recursively in src directory of given format using nseconds sampled from the audio file .