import matplotlib.gridspec as gridspec from matplotlib.cm import ScalarMappable from audiopack import audio_chunks, loadwav, spectrum try: soundfile = sys.argv[1] except IndexError: print("no audiofile provided") sys.exit() else: try: mode = sys.argv[2] except IndexError: mode = 'freq' meta, data = loadwav(soundfile) t = np.linspace(0, meta.seconds, meta.samples) print("Samplerate: %d" % meta.rate) print("Channels: %d" % meta.channels) print("Length: %d samples, %d seconds" % (meta.samples, meta.seconds)) fig = plt.figure() gs = gridspec.GridSpec(meta.channels, 1) # time/signal view if mode[:4] == 'freq': for i, channel in enumerate(data.T): ax = plt.Subplot(fig, gs[i]) ax.plot(t, channel) fig.add_subplot(ax)
dest='thickness', type=float, action='store', default=1, help='threshold. if set to zero, values are grayscaled') parser.add_argument( '-s', '--spread', dest='spread', type=float, action='store', default=1., help='spread. if set to zero will try and follow block energy') args = parser.parse_args() meta, data = loadwav(args.soundfile) print("Samplerate: %d" % meta.rate) print("Channels: %d" % meta.channels) print("Length: %d samples, %d seconds" % (meta.samples, meta.seconds)) blocksize = meta.rate // args.fps blocks = meta.samples // blocksize print("%d Frames at %d samples" % (blocks, blocksize)) term_width = 100 N = blocksize T = 1.0 / blocksize * 1.25 for n, b in enumerate(audio_chunks(data, blocksize)): img = np.zeros((args.height, args.width, 3), np.uint8)
'--length', dest='length', type=int, action='store', default=0, help='length') parser.add_argument('-r', '--rate', dest='rate', type=float, action='store', help='rate') args = parser.parse_args() image = np.zeros((args.height, args.width, 3), dtype=np.uint8) meta, audio = ap.loadwav(args.audiofile) blocksize = meta.rate // args.fps blocks = meta.samples // blocksize scroll = blocksize // args.height last_img = None for i, block in enumerate(ap.audio_chunks(audio, blocksize)): img = last_img if last_img is not None else image img = render_frame( img, block.T[0] if meta.channels > 1 else block, blocksize, args.width, args.height, raw=args.raw, )