Update app.py
Browse files
app.py
CHANGED
|
@@ -112,12 +112,13 @@ def arabic_tts(arabic_text):
|
|
| 112 |
|
| 113 |
try:
|
| 114 |
tts = gTTS(text=arabic_text, lang='ar', slow=False)
|
| 115 |
-
# Create temporary file
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
| 119 |
except Exception as e:
|
| 120 |
-
print(f"TTS Error: {e}")
|
| 121 |
return None
|
| 122 |
|
| 123 |
def ipa_tts(ipa_text):
|
|
@@ -129,9 +130,10 @@ def ipa_tts(ipa_text):
|
|
| 129 |
# Use English TTS for IPA - this is an approximation
|
| 130 |
# For better IPA pronunciation, you'd need specialized TTS engines
|
| 131 |
tts = gTTS(text=ipa_text, lang='en', slow=True)
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
| 135 |
except Exception as e:
|
| 136 |
print(f"IPA TTS Error: {e}")
|
| 137 |
return None
|
|
@@ -266,6 +268,17 @@ with gr.Blocks(title="Arabic Transliterator") as demo:
|
|
| 266 |
outputs=[arabic_output, ipa_output, arabic_audio, ipa_audio]
|
| 267 |
)
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
if __name__ == "__main__":
|
| 271 |
demo.launch()
|
|
|
|
| 112 |
|
| 113 |
try:
|
| 114 |
tts = gTTS(text=arabic_text, lang='ar', slow=False)
|
| 115 |
+
# Create temporary file with proper cleanup
|
| 116 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 117 |
+
temp_path = tmp_file.name
|
| 118 |
+
tts.save(temp_path)
|
| 119 |
+
return temp_path
|
| 120 |
except Exception as e:
|
| 121 |
+
print(f"Arabic TTS Error: {e}")
|
| 122 |
return None
|
| 123 |
|
| 124 |
def ipa_tts(ipa_text):
|
|
|
|
| 130 |
# Use English TTS for IPA - this is an approximation
|
| 131 |
# For better IPA pronunciation, you'd need specialized TTS engines
|
| 132 |
tts = gTTS(text=ipa_text, lang='en', slow=True)
|
| 133 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 134 |
+
temp_path = tmp_file.name
|
| 135 |
+
tts.save(temp_path)
|
| 136 |
+
return temp_path
|
| 137 |
except Exception as e:
|
| 138 |
print(f"IPA TTS Error: {e}")
|
| 139 |
return None
|
|
|
|
| 268 |
outputs=[arabic_output, ipa_output, arabic_audio, ipa_audio]
|
| 269 |
)
|
| 270 |
|
| 271 |
+
# Examples
|
| 272 |
+
gr.Examples(
|
| 273 |
+
examples=[
|
| 274 |
+
["ahlan wa sahlan"],
|
| 275 |
+
["as-salamu alaykum"],
|
| 276 |
+
["shukran jazeelan"],
|
| 277 |
+
["kayf halak"],
|
| 278 |
+
["ana min amreeka"]
|
| 279 |
+
],
|
| 280 |
+
inputs=latin_input
|
| 281 |
+
)
|
| 282 |
|
| 283 |
if __name__ == "__main__":
|
| 284 |
demo.launch()
|