def generate(): music = request.files.get('music') # had upload file if hasattr(music, "file"): basename, extension = os.path.splitext(music.filename) # valid the extension if extension.lower() in ['.wav', '.aiff', '.au', '.ogg', '.flac', '.mp3']: raw = music.file.read() filename = md5(raw) # write upload file into attachment root f = open("%s/%s%s" % (ATTACHMENT_ROOT, filename, extension), "w") f.write(raw) f.close() # Draw wave image waveform.draw( "%s/%s%s" % (ATTACHMENT_ROOT, filename, extension), "%s/%s%s" % (ATTACHMENT_ROOT, filename, ".png"), (700, 100), bgColor=(0,0,0,0), fgColor=(0,0,128,255) ) # Save filename into cookie for preview response.set_cookie("filename", music.filename) redirect('/preview/%s' % filename) else: redirect('/error/invalid-upload-file') redirect('/error/no-upload-file')
try: import waveform except ImportError, exc: raise ImportError( "%s [get it at https://github.com/superjoe30/PyWaveform]" % exc) outdir = outdir or os.path.dirname(mediafile) outfile = os.path.join( outdir, os.path.splitext(os.path.basename(mediafile))[0] + ".png") with transcode.to_wav(mediafile) as wavfile: # Draw using a gradient waveform.draw(wavfile, outfile, xy_size, bgColor=bg_color or WAVE_BG_COLOR, fgGradientCenter=center_color or WAVE_CENTER_COLOR, fgGradientOuter=outer_color or WAVE_OUTER_COLOR) return outfile def waveform_stack(mediafiles, xy_size, output=None, label_style=None, center_color=None, outer_color=None, bg_color=None): """ Create a stack of waveform images from audio data. Return path to created image file.
def waveform_image(mediafile, xy_size, outdir=None, center_color=None, outer_color=None, bg_color=None): """ Create waveform image from audio data. Return path to created image file. """ try: import waveform except ImportError, exc: raise ImportError("%s [get it at https://github.com/superjoe30/PyWaveform]" % exc) outdir = outdir or os.path.dirname(mediafile) outfile = os.path.join(outdir, os.path.splitext(os.path.basename(mediafile))[0] + ".png") with transcode.to_wav(mediafile) as wavfile: # Draw using a gradient waveform.draw(wavfile, outfile, xy_size, bgColor=bg_color or WAVE_BG_COLOR, fgGradientCenter=center_color or WAVE_CENTER_COLOR, fgGradientOuter=outer_color or WAVE_OUTER_COLOR) return outfile def waveform_stack(mediafiles, xy_size, output=None, label_style=None, center_color=None, outer_color=None, bg_color=None): """ Create a stack of waveform images from audio data. Return path to created image file. """ img_files = [] output = output or os.path.abspath(os.path.dirname(os.path.commonprefix(mediafiles))) if os.path.isdir(output): output = os.path.join(output, "waveforms.jpg") cmd = [config.CMD_IM_MONTAGE] + shlex.split(label_style or WAVE_LABEL_STYLE)