Niansuh commited on
Commit
b2d49c3
·
verified ·
1 Parent(s): e65b5bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -82,22 +82,17 @@ tts_provider = ElevenlabsTTS()
82
  @app.route('/', methods=['GET', 'POST'])
83
  def index():
84
  if request.method == 'POST':
85
- if 'generate' in request.form:
86
- text = request.form.get('text')
87
- voice = request.form.get('voice', 'Brian')
88
- try:
89
- audio_file = tts_provider.tts(text, voice)
90
- return send_file(audio_file, mimetype='audio/mpeg', as_attachment=True, download_name=f"{voice}_output.mp3")
91
- except Exception as e:
92
- return render_template('index.html', error=str(e), voices=tts_provider.all_voices.keys())
93
- elif 'preview' in request.form:
94
- voice = request.form.get('preview_voice')
95
- try:
96
- preview_text = f"Hello, this is {voice}'s voice sample."
97
- audio_file = tts_provider.tts(preview_text, voice)
98
- return send_file(audio_file, mimetype='audio/mpeg', as_attachment=False)
99
- except Exception as e:
100
- return render_template('index.html', error=str(e), voices=tts_provider.all_voices.keys())
101
  return render_template('index.html', voices=tts_provider.all_voices.keys())
102
 
103
  if __name__ == "__main__":
 
82
  @app.route('/', methods=['GET', 'POST'])
83
  def index():
84
  if request.method == 'POST':
85
+ text = request.form.get('text')
86
+ voice = request.form.get('voice', 'Brian')
87
+ try:
88
+ audio_file = tts_provider.tts(text, voice)
89
+ return render_template('index.html',
90
+ audio_file=audio_file,
91
+ voices=tts_provider.all_voices.keys(),
92
+ text=text,
93
+ voice=voice)
94
+ except Exception as e:
95
+ return render_template('index.html', error=str(e), voices=tts_provider.all_voices.keys())
 
 
 
 
 
96
  return render_template('index.html', voices=tts_provider.all_voices.keys())
97
 
98
  if __name__ == "__main__":