/examples/summary/summary.py

http://echo-nest-remix.googlecode.com/ · Python · 51 lines · 35 code · 7 blank · 9 comment · 7 complexity · badc43cfb70b49d22355051b12a0ab71 MD5 · raw file

  1. #!/usr/bin/env python
  2. # encoding: utf=8
  3. """
  4. summary.py
  5. Digest only the first or only the second tatum of every beat.
  6. By Ben Lacker, 2009-02-18.
  7. """
  8. import sys
  9. import echonest.audio as audio
  10. from echonest.selection import have_pitch_max,have_pitches_max
  11. usage = """
  12. Usage:
  13. python summary.py [and] <input_filename> <output_filename>
  14. Example:
  15. python summary.py RichGirl.mp3 RichSummary.mp3
  16. """
  17. def main(input_filename, output_filename, index):
  18. audio_file = audio.LocalAudioFile(input_filename)
  19. beats = audio_file.analysis.beats
  20. collect = audio.AudioQuantumList()
  21. for beat in beats:
  22. tata = beat.children()
  23. if len(tata)>1:
  24. tat = tata[index]
  25. else:
  26. tat = tata[0]
  27. collect.append(tat)
  28. out = audio.getpieces(audio_file, collect)
  29. out.encode(output_filename)
  30. if __name__ == '__main__':
  31. try:
  32. if sys.argv[1]=='and':
  33. index = 1
  34. else:
  35. index = 0
  36. input_filename = sys.argv[-2]
  37. output_filename = sys.argv[-1]
  38. except:
  39. print usage
  40. sys.exit(-1)
  41. main(input_filename, output_filename, index)