/examples/one/one.py

http://echo-nest-remix.googlecode.com/ · Python · 38 lines · 26 code · 3 blank · 9 comment · 3 complexity · 2daa3f91f4a8892dacdfd518af39c600 MD5 · raw file

  1. #!/usr/bin/env python
  2. # encoding: utf=8
  3. """
  4. one.py
  5. Digest only the first beat of every bar.
  6. By Ben Lacker, 2009-02-18.
  7. """
  8. import echonest.audio as audio
  9. from echonest.selection import have_pitch_max,have_pitches_max
  10. usage = """
  11. Usage:
  12. python one.py <input_filename> <output_filename>
  13. Example:
  14. python one.py EverythingIsOnTheOne.mp3 EverythingIsReallyOnTheOne.mp3
  15. """
  16. def main(input_filename, output_filename):
  17. audiofile = audio.LocalAudioFile(input_filename)
  18. bars = audiofile.analysis.bars
  19. collect = audio.AudioQuantumList()
  20. for bar in bars:
  21. collect.append(bar.children()[0])
  22. out = audio.getpieces(audiofile, collect)
  23. out.encode(output_filename)
  24. if __name__ == '__main__':
  25. import sys
  26. try:
  27. input_filename = sys.argv[1]
  28. output_filename = sys.argv[2]
  29. except:
  30. print usage
  31. sys.exit(-1)
  32. main(input_filename, output_filename)