File size: 545 Bytes
4345f75
e59d451
83b2559
4345f75
 
e59d451
 
 
 
4345f75
 
 
 
 
e59d451
4345f75
 
 
e59d451
 
4345f75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from flask import Flask, request, send_file
from flask_cors import CORS
import edge_tts
import asyncio
import uuid

app = Flask(__name__)
CORS(app)

@app.route('/tts', methods=['POST'])
def tts():
    text = request.json.get('text', '').strip()
    if not text:
        return {'error': 'No text'}, 400
    
    filename = f"{uuid.uuid4()}.mp3"
    asyncio.run(edge_tts.Communicate(text, 'en-US-JennyNeural').save(filename))
    return send_file(filename, mimetype='audio/mpeg')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)