Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
from flask import Flask, request, jsonify
|
2 |
from AudioGeneration import generate_audio
|
3 |
-
import os
|
4 |
import uuid
|
|
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
@@ -11,23 +11,18 @@ def generate_audio_endpoint():
|
|
11 |
data = request.get_json()
|
12 |
text = data.get("text", "").strip()
|
13 |
if not text:
|
14 |
-
return jsonify({"error": "Text
|
15 |
|
16 |
filename = f"{uuid.uuid4().hex}.wav"
|
17 |
audio_path = generate_audio(text, filename)
|
18 |
-
|
19 |
-
return
|
20 |
except Exception as e:
|
21 |
return jsonify({"error": str(e)}), 500
|
22 |
|
23 |
-
@app.route("/audio/<filename>")
|
24 |
-
def serve_audio(filename):
|
25 |
-
return app.send_static_file(f"audio/{filename}")
|
26 |
-
|
27 |
@app.route("/")
|
28 |
def root():
|
29 |
-
return jsonify({"message": "
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
-
os.makedirs("static/audio", exist_ok=True)
|
33 |
app.run(host="0.0.0.0", port=7860)
|
|
|
1 |
+
from flask import Flask, request, jsonify, send_file
|
2 |
from AudioGeneration import generate_audio
|
|
|
3 |
import uuid
|
4 |
+
import os
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
|
|
11 |
data = request.get_json()
|
12 |
text = data.get("text", "").strip()
|
13 |
if not text:
|
14 |
+
return jsonify({"error": "Text is empty"}), 400
|
15 |
|
16 |
filename = f"{uuid.uuid4().hex}.wav"
|
17 |
audio_path = generate_audio(text, filename)
|
18 |
+
|
19 |
+
return send_file(audio_path, mimetype="audio/wav")
|
20 |
except Exception as e:
|
21 |
return jsonify({"error": str(e)}), 500
|
22 |
|
|
|
|
|
|
|
|
|
23 |
@app.route("/")
|
24 |
def root():
|
25 |
+
return jsonify({"message": "Text-to-Speech API is running."})
|
26 |
|
27 |
if __name__ == "__main__":
|
|
|
28 |
app.run(host="0.0.0.0", port=7860)
|