def synthesis_post(): global model, waveglow_model if not model: return redirect("/synthesis-setup") if request.method == "GET": return render_template("synthesis.html") else: text = request.form["text"] folder_name = get_suffix() results_folder = os.path.join(paths["results"], folder_name) os.makedirs(results_folder) graph_path = os.path.join(results_folder, GRAPH_FILE) audio_path = os.path.join(results_folder, RESULTS_FILE) graph_web_path = graph_path.replace("\\", "/") audio_web_path = audio_path.replace("\\", "/") synthesize(model, waveglow_model, text, inflect_engine, graph_path, audio_path) return render_template( "synthesis.html", text=text.strip(), alertnative_words=get_alternative_word_suggestions( audio_path, text), graph=graph_web_path, audio=audio_web_path, )
def create_dataset_post(): min_confidence = request.form["confidence"] if request.form["name"]: output_folder = os.path.join(paths["datasets"], request.form["name"]) if os.path.exists(output_folder): request.files = None raise Exception("Dataset name taken") os.makedirs(output_folder, exist_ok=True) text_path = os.path.join(output_folder, TEXT_FILE) audio_path = os.path.join(output_folder, AUDIO_FILE) forced_alignment_path = os.path.join(output_folder, ALIGNMENT_FILE) output_path = os.path.join(output_folder, AUDIO_FOLDER) label_path = os.path.join(output_folder, METADATA_FILE) info_path = os.path.join(output_folder, INFO_FILE) request.files["text_file"].save(text_path) request.files["audio_file"].save(audio_path) start_progress_thread( create_dataset, text_path=text_path, audio_path=audio_path, forced_alignment_path=forced_alignment_path, output_path=output_path, label_path=label_path, info_path=info_path, min_confidence=float(min_confidence), ) else: output_folder = os.path.join(paths["datasets"], request.form["path"]) suffix = get_suffix() text_path = os.path.join(output_folder, f"text-{suffix}.txt") audio_path = os.path.join(output_folder, f"audio-{suffix}.mp3") forced_alignment_path = os.path.join(output_folder, f"align-{suffix}.json") info_path = os.path.join(output_folder, INFO_FILE) request.files["text_file"].save(text_path) request.files["audio_file"].save(audio_path) existing_output_path = os.path.join(output_folder, AUDIO_FOLDER) existing_label_path = os.path.join(output_folder, METADATA_FILE) start_progress_thread( extend_existing_dataset, text_path=text_path, audio_path=audio_path, forced_alignment_path=forced_alignment_path, output_path=existing_output_path, label_path=existing_label_path, suffix=suffix, info_path=info_path, min_confidence=float(min_confidence), ) return render_template("progress.html", next_url=get_next_url(URLS, request.path))
def synthesis_post(): global model, vocoder, symbols if not model or not vocoder or not symbols: return redirect("/synthesis-setup") if request.method == "GET": return render_template("synthesis.html") else: text = request.form.getlist("text") if len(text) == 1: text = text[0] method = request.form["text_method"] split_text = method == "paragraph" parent_folder = os.path.join(paths["results"], datetime.now().strftime("%Y-%m")) os.makedirs(parent_folder, exist_ok=True) first_line = text[0] if type(text) == list else text results_folder = os.path.join( parent_folder, get_suffix() + "-" + re.sub("[^0-9a-zA-Z _]+", "", first_line.replace(" ", "_"))[:20]) os.makedirs(results_folder) graph_path = os.path.join(results_folder, GRAPH_FILE) audio_path = os.path.join(results_folder, RESULTS_FILE) graph_web_path = os.path.relpath(graph_path).replace("\\", "/") audio_web_path = os.path.relpath(audio_path).replace("\\", "/") silence = float(request.form["silence"]) max_decoder_steps = int(request.form["max_decoder_steps"]) synthesize( model, text, symbols, graph_path, audio_path, vocoder, silence, max_decoder_steps=max_decoder_steps, split_text=split_text, ) return render_template( "synthesis.html", text=text, method=method, graph=graph_web_path, audio=audio_web_path, silence=silence, max_decoder_steps=max_decoder_steps, )
def create_dataset_post(): min_confidence = float(request.form["confidence"]) language = request.form["language"] combine_clips = request.form.get("combine_clips") is not None min_length = float(request.form["min_length"]) max_length = float(request.form["max_length"]) transcription_model = ( Silero(language) if language in SILERO_LANGUAGES else DeepSpeech( os.path.join(paths["languages"], language, TRANSCRIPTION_MODEL))) symbols = get_symbols(language) text_file = SUBTITLE_FILE if request.files["text_file"].filename.endswith( ".srt") else TEXT_FILE if request.form["name"]: output_folder = os.path.join(paths["datasets"], request.form["name"]) if os.path.exists(output_folder): request.files = None raise Exception("Dataset name taken") os.makedirs(output_folder, exist_ok=True) text_path = os.path.join(output_folder, text_file) audio_path = os.path.join(output_folder, request.files["audio_file"].filename) with open(text_path, "w", encoding=CHARACTER_ENCODING) as f: f.write(request.files["text_file"].read().decode( CHARACTER_ENCODING, "ignore").replace("\r\n", "\n")) request.files["audio_file"].save(audio_path) start_progress_thread( create_dataset, text_path=text_path, audio_path=audio_path, transcription_model=transcription_model, output_folder=output_folder, min_length=min_length, max_length=max_length, min_confidence=min_confidence, combine_clips=combine_clips, symbols=symbols, ) else: output_folder = os.path.join(paths["datasets"], request.form["dataset"]) suffix = get_suffix() text_path = os.path.join(output_folder, add_suffix(text_file, suffix)) audio_path = os.path.join( output_folder, add_suffix(request.files["audio_file"].filename, suffix)) with open(text_path, "w", encoding=CHARACTER_ENCODING) as f: f.write(request.files["text_file"].read().decode( CHARACTER_ENCODING, "ignore").replace("\r\n", "\n")) request.files["audio_file"].save(audio_path) start_progress_thread( extend_existing_dataset, text_path=text_path, audio_path=audio_path, transcription_model=transcription_model, output_folder=output_folder, suffix=suffix, min_length=min_length, max_length=max_length, min_confidence=min_confidence, combine_clips=combine_clips, symbols=symbols, ) return render_template("progress.html", next_url=get_next_url(URLS, request.path))