2506minecraft commited on
Commit
62fb309
·
verified ·
1 Parent(s): 5180e89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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
- inputs = tts_model(text, return_tensors="pt")
98
- with torch.no_grad():
99
- output = tts_model.generate(**inputs)
100
- waveform = output[0].numpy()
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
- if not user_text:
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