Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,28 +53,25 @@ def api_ocr():
|
|
| 53 |
except Exception as e:
|
| 54 |
return jsonify({"error": str(e)}), 500
|
| 55 |
|
| 56 |
-
# 4. 🎙️ VIP Voice Generator API (Direct Python
|
| 57 |
@app.route('/tts', methods=['POST'])
|
| 58 |
-
def
|
| 59 |
try:
|
| 60 |
-
text = request.form
|
| 61 |
rate = request.form.get('rate', '+0%')
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
await communicate.save(audio_file)
|
| 68 |
|
| 69 |
-
asyncio.run(
|
| 70 |
-
|
| 71 |
-
with open(audio_file, 'rb') as f:
|
| 72 |
-
data = f.read()
|
| 73 |
-
os.remove(audio_file)
|
| 74 |
-
return send_file(io.BytesIO(data), mimetype='audio/mpeg')
|
| 75 |
except Exception as e:
|
| 76 |
-
|
| 77 |
-
return jsonify({"error": str(e)}), 500
|
| 78 |
|
| 79 |
# HF ki app.py mein ye naya endpoint jodo
|
| 80 |
@app.route('/enhance', methods=['POST'])
|
|
|
|
| 53 |
except Exception as e:
|
| 54 |
return jsonify({"error": str(e)}), 500
|
| 55 |
|
| 56 |
+
# 4. 🎙️ VIP Voice Generator API (Direct Python)
|
| 57 |
@app.route('/tts', methods=['POST'])
|
| 58 |
+
def tts_api():
|
| 59 |
try:
|
| 60 |
+
text = request.form.get('text', 'Hello')
|
| 61 |
rate = request.form.get('rate', '+0%')
|
| 62 |
+
# 👇 Yahan 'SwaraNeural' laga diya hai jo ekdum sweet Indian female voice hai
|
| 63 |
+
voice = request.form.get('voice', 'hi-IN-SwaraNeural')
|
| 64 |
+
|
| 65 |
+
audio_file = "temp_tts.ogg"
|
| 66 |
+
|
| 67 |
+
async def generate_audio():
|
| 68 |
+
communicate = edge_tts.Communicate(text, voice, rate=rate)
|
| 69 |
await communicate.save(audio_file)
|
| 70 |
|
| 71 |
+
asyncio.run(generate_audio())
|
| 72 |
+
return send_file(audio_file, mimetype="audio/ogg")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
except Exception as e:
|
| 74 |
+
return str(e), 500
|
|
|
|
| 75 |
|
| 76 |
# HF ki app.py mein ye naya endpoint jodo
|
| 77 |
@app.route('/enhance', methods=['POST'])
|