PageRenderTime 214ms CodeModel.GetById 111ms app.highlight 4ms RepoModel.GetById 97ms app.codeStats 0ms

/examples/summary/summary.py

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