def common_main(script_name, files, argv): assert len( argv ) >= 2, "Usage: python {} folder [filename1] [filename2]...".format( script_name) folder = argv[1] if len(argv) == 3: filenames = argv[2:] else: filenames = None if not os.path.exists(folder): os.mkdir(folder) for name, value in files.items(): if value.stream is not None and (filenames is None or name in filenames): print "Writing " + value.filename with open(os.path.join(folder, value.filename), 'wb') as f: audiogen.sampler.write_wav( f, envelope(envelope(sound(), value.stream), constant(0.01))) print "Done" else: print "Skipping " + value.filename return 0
def encode(binary_data): ''' Encode binary data using Bell-202 AFSK Expects a bitarray.bitarray() object of binary data as its argument. Returns a generator of sound samples suitable for use with the audiogen module. ''' framed_data = frame(binary_data) # set volume to 1/2, preceed packet with 1/20 s silence to allow for startup glitches for sample in itertools.chain( audiogen.silence(1.05), multiply(modulate(framed_data), constant(0.5)), audiogen.silence(1.05), ): yield sample
#!/usr/bin/python import audiogen import sys from audiogen.util import constant #audiogen.sampler.write_wav(sys.stdout, audiogen.tone(440)) audiogen.sampler.play( audiogen.util.mixer((audiogen.tone(50), audiogen.tone(52)), [ (constant(0.3), constant(0.3)), ]))