def drawSound(sound, startTime, endTime): # Get URL parameters showSpectrogram = '0' if request.args.get("spectrogram") is None else '1' showPitch = '0' if request.args.get("pitch") is None else '1' showIntensity = '0' if request.args.get("intensity") is None else '1' showFormants = '0' if request.args.get("formants") is None else '1' showPulses = '0' if request.args.get("pulses") is None else '1' # Script file script = praat._scripts_dir + "drawSpectrogram" # Parameters to the script params = [ sound, startTime, endTime, showSpectrogram, showPitch, showIntensity, showFormants, showPulses, praat._sounds_dir, praat._images_dir ] # Image name will be a combination of relevant params joined by a period. image = praat._images_dir + ".".join(params[:-2]) + ".png" # Add image name to params list params.append(image) # If image does not exist, run script if not os.path.isfile(image): praat.runScript(script, params) utils.resizeImage(image) # Image should be available now, generated or cached resp = app.make_response(open(image).read()) resp.content_type = "image/png" return resp
def drawElan(sound, startTime, endTime): #if(endTime<0) #resp = drawSound1(sound) showPitch = '0' # Script file script = praat._scripts_dir + "drawWaveform" # Parameters to the script params = [ sound, startTime, endTime, showPitch, praat._sounds_dir, praat._images_dir ] # Image name will be a combination of relevant params joined by a period. if "wav" not in sound: image = praat._images_dir + str(sound.replace("mp3", "png")) else: image = praat._images_dir + str(sound.replace("wav", "png")) # Add image name to params list params.append(image) # If image does not exist, run script if not os.path.isfile(image): praat.runScript(script, params) utils.resizeImage(image) # Image should be available now, generated or cached resp = app.make_response(open(image).read()) resp.content_type = "image/png" return resp
def waveform(sound): startTime = request.args.get('startTime', '0') endTime = request.args.get('endTime', '0') if float(startTime) > float(endTime): endTime = startTime script = praat._scripts_dir + 'drawWave' params = [sound, startTime, endTime, praat._sounds_dir, praat._images_dir] ts = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S_") if "wav" not in sound: image = praat._images_dir + ts + str(sound.replace("mp3", "png")) else: image = praat._images_dir + ts + str(sound.replace("wav", "png")) # Add image name to params list params.append(image) # If image does not exist, run script #if not os.path.isfile(image): praat.runScript(script, params) utils.resizeImage(image, (1280, 640)) #utils.cropImage(image) # Image should be available now, generated or cached with open(image) as fp: resp = app.make_response(fp.read()) utils.rm_rf(image) resp.content_type = "image/png" return resp
def audio_version_handler(aid, vid): storage_svc = get_storage_service(praat.app.config) result = storage_svc.get(aid, vid) if result is None: return jsonify({"status": "fail", "message": "Audio version does not exist"}) audio = praat.Audio.query.get(aid) resp = app.make_response(result['data']) resp.content_type = "audio/" + utils.fileType(audio.name) return resp
def drawSound1(sound): image = show_wave_n_spec(sound) print(image) utils.resizeImage(image) # Image should be available now, generated or cached resp = app.make_response(open(image).read()) print(resp) #resp.content_type = "image/png" return send_file(image, mimetype='image/png')
def playSound(sound): # Get the path to the sound file fullpath = praat._sounds_dir + sound ## added to test play functionality using praat script #script = praat._scripts_dir + "test" #params = [sound, praat._sounds_dir] #praat.runScript(script, params) # Open stream to file resp = app.make_response(open(fullpath).read()) # Set file type like audio/mp3 or audio/wav resp.content_type = "audio/" + utils.fileType(sound) #print str(resp.content_type) #print str(resp) return resp
def audio_waveform_handler(aid, vid): storage_svc = get_storage_service(praat.app.config) waveform_name = aid + vid + '.png' resp = app.make_response(storage_svc.get(waveform_name)['data']) resp.content_type = "image/png" return resp