Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -94,11 +94,10 @@ async def generate_response(text: str, user_id: str) -> str:
|
|
94 |
|
95 |
async def text_to_speech(text: str) -> None:
|
96 |
try:
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
sf.write("bot_response.wav", waveform, tts_model.config.sampling_rate)
|
102 |
except Exception as e:
|
103 |
logger.error(f"فشل تحويل النص إلى صوت: {str(e)}")
|
104 |
|
@@ -113,7 +112,7 @@ async def process_voice(update: Update, context):
|
|
113 |
await voice_file.download_to_drive("user_voice.ogg")
|
114 |
|
115 |
user_text = await speech_to_text("user_voice.ogg")
|
116 |
-
|
117 |
await update.message.reply_text(" لم أتمكن من فهم الصوت. يرجى المحاولة مرة أخرى.")
|
118 |
return
|
119 |
|
|
|
94 |
|
95 |
async def text_to_speech(text: str) -> None:
|
96 |
try:
|
97 |
+
# استخدام نموذج تحويل النص إلى صوت
|
98 |
+
tts_pipeline = pipeline("text-to-speech", model="coqui/tts-arabic", token=os.getenv("HF_TOKEN"))
|
99 |
+
audio = tts_pipeline(text)
|
100 |
+
sf.write("bot_response.wav", audio, 22050) # تأكد من استخدام معدل العينة الصحيح
|
|
|
101 |
except Exception as e:
|
102 |
logger.error(f"فشل تحويل النص إلى صوت: {str(e)}")
|
103 |
|
|
|
112 |
await voice_file.download_to_drive("user_voice.ogg")
|
113 |
|
114 |
user_text = await speech_to_text("user_voice.ogg")
|
115 |
+
if not user_text:
|
116 |
await update.message.reply_text(" لم أتمكن من فهم الصوت. يرجى المحاولة مرة أخرى.")
|
117 |
return
|
118 |
|