Skip to content

Commit cc38a85

Browse files
committed
TTS Re-implementation
1 parent dfd731c commit cc38a85

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

web.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import traceback
99
from flask import send_file
1010
import io
11+
from gtts import gTTS
1112

1213
# --- Logging Setup ---
1314
logging.basicConfig(level=logging.INFO,
@@ -176,6 +177,24 @@ def api_delete_chat(chat_id):
176177
os.remove(path)
177178
return jsonify({'success': True})
178179

180+
@app.route('/tts', methods=['POST'])
181+
def text_to_speech():
182+
data = request.get_json()
183+
text = data.get('text', '')
184+
if not text:
185+
return jsonify({'error': 'No text provided'}), 400
186+
try:
187+
# Generate speech using gTTS
188+
tts = gTTS(text=text, lang='en')
189+
mp3_fp = io.BytesIO()
190+
tts.write_to_fp(mp3_fp)
191+
mp3_fp.seek(0)
192+
# Return the audio file as response
193+
return send_file(mp3_fp, mimetype='audio/mpeg', as_attachment=False, download_name='speech.mp3')
194+
except Exception as e:
195+
logger.error(f"Error generating speech: {e}", exc_info=True)
196+
return jsonify({'error': 'Failed to generate speech'}), 500
197+
179198
if __name__ == '__main__':
180199
if orchestrator:
181200
logger.info("Starting Flask development server...")

0 commit comments

Comments
 (0)