Move hint up in preparation for state mode display (i.e. puzzle vs difficulty).
[naja.git] / tools / gen_sound.py
1 #!/usr/bin/env python
2
3 from subprocess import Popen, PIPE
4 import os
5 import sys
6
7
8 def gen_raw(description):
9     for chunk in description:
10         for blob in chunk.raw():
11             yield blob
12
13
14 def encode(filename, data):
15     print "Writing %s" % filename
16     p = Popen(('oggenc', '-o', filename, '--raw', '--quiet', '-'),
17               stdin=PIPE, cwd='data/sounds')
18     for blob in data:
19         p.stdin.write(blob)
20     p.stdin.close()
21     assert p.wait() == 0
22
23
24 def write(basename, description):
25     return encode('%s.ogg' % basename, gen_raw(description))
26
27
28 def main():
29     sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
30     from data.sounds import SOUNDS
31     from naja.gen_sound import Chunk
32
33     sounds = SOUNDS.keys()
34     if len(sys.argv) > 1:
35         sounds = sys.argv[1:]
36     for sound in sounds:
37         description = SOUNDS[sound]
38         if isinstance(description, Chunk):
39             description = (description,)
40         write(sound, description)
41
42
43 if __name__ == '__main__':
44     main()