-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
67 lines (57 loc) · 2.31 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# app.py
from flask import Flask, render_template, request, send_file, redirect, url_for, flash
from werkzeug.utils import secure_filename
import os
from main import process_tts
from vocalshift import vocal_shift
app = Flask(__name__)
app.secret_key = 'supersecretkey'
UPLOAD_FOLDER = 'uploads'
OUTPUT_FOLDER = 'output'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['OUTPUT_FOLDER'] = OUTPUT_FOLDER
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
text = request.form.get('text')
language = request.form.get('language', 'en')
speaker_file = request.files.get('speaker')
audio_file = request.files.get('audio')
output_filename = 'output.wav'
output_path = os.path.join(app.config['OUTPUT_FOLDER'], output_filename)
speaker_path = None
if speaker_file:
speaker_filename = secure_filename(speaker_file.filename)
speaker_path = os.path.join(app.config['UPLOAD_FOLDER'], speaker_filename)
speaker_file.save(speaker_path)
if audio_file:
audio_filename = secure_filename(audio_file.filename)
audio_path = os.path.join(app.config['UPLOAD_FOLDER'], audio_filename)
audio_file.save(audio_path)
success = vocal_shift(
input_audio=audio_path,
output_audio=output_path,
stt_model_size='base',
speaker=speaker_path,
effect=None,
effect_level=1.0
)
else:
if not text:
flash('Text is required!', 'danger')
return redirect(url_for('index'))
# Perform TTS conversion using main.py
success = process_tts(text, output_path, speaker_path, language)
if success:
return redirect(url_for('download_file', filename=output_filename))
else:
flash('Conversion failed', 'danger')
return redirect(url_for('index'))
return render_template('index.html')
@app.route('/download/<filename>')
def download_file(filename):
return send_file(os.path.join(app.config['OUTPUT_FOLDER'], filename), as_attachment=True)
if __name__ == '__main__':
app.run(debug=True)