Mercurial > boomslang
comparison tools/gen_sound.py @ 552:15713dfe555d pyntnclick
The new, friendlier gen_sound helper
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sat, 11 Feb 2012 13:30:56 +0200 |
parents | 5b9f371c2bb8 |
children |
comparison
equal
deleted
inserted
replaced
551:38fb04728ac5 | 552:15713dfe555d |
---|---|
25 data.append(struct.pack('<i', y)) | 25 data.append(struct.pack('<i', y)) |
26 output = open(filename, 'w') | 26 output = open(filename, 'w') |
27 for x in range(int(freq * secs)): | 27 for x in range(int(freq * secs)): |
28 output.write(''.join(data)) | 28 output.write(''.join(data)) |
29 output.close() | 29 output.close() |
30 return filename | |
30 | 31 |
31 | 32 |
33 def usage(): | |
34 print 'Unexpected input' | |
35 print 'Usage: gen_sound.py <freq> [<length>]' | |
36 print ' where <freq> is the frequency in Hz (integer)' | |
37 print ' and [<length>] is the time is seconds (float)' | |
38 | |
32 if __name__ == "__main__": | 39 if __name__ == "__main__": |
33 freq = int(sys.argv[1]) | 40 try: |
41 freq = int(sys.argv[1]) | |
42 except Exception, exc: | |
43 usage() | |
44 print 'Error was: %s' % exc | |
45 sys.exit(1) | |
46 | |
34 if len(sys.argv) > 2: | 47 if len(sys.argv) > 2: |
35 secs = float(sys.argv[2]) | 48 try: |
49 secs = float(sys.argv[2]) | |
50 except Exception, exc: | |
51 usage() | |
52 print 'Error was: %s' % exc | |
53 sys.exit(1) | |
36 else: | 54 else: |
37 secs = 0.25 | 55 secs = 0.25 |
38 gen_sine(freq, secs) | 56 output = gen_sine(freq, secs) |
57 print 'Wrote sample to %s' % output |