Singhp08 commited on
Commit
75378bf
·
verified ·
1 Parent(s): 51b943d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
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 Engine)
57
  @app.route('/tts', methods=['POST'])
58
- def api_tts():
59
  try:
60
- text = request.form['text']
61
  rate = request.form.get('rate', '+0%')
62
- audio_file = f"temp_{os.urandom(4).hex()}.mp3"
63
-
64
- # Subprocess hata kar direct Async Python engine lagaya
65
- async def generate_voice():
66
- communicate = edge_tts.Communicate(text, "hi-IN-MadhurNeural", rate=rate)
 
 
67
  await communicate.save(audio_file)
68
 
69
- asyncio.run(generate_voice())
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
- print(f"Voice Crash: {e}")
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'])