moshabann commited on
Commit
2f6457f
·
verified ·
1 Parent(s): 46395c6

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +3 -20
app.js CHANGED
@@ -439,7 +439,7 @@ function sendMessage() {
439
  input.value = '';
440
 
441
  // استدعاء الذكاء الاصطناعي عبر الخادم
442
- fetch('http://localhost:5000/chat', {
443
  method: 'POST',
444
  headers: {'Content-Type': 'application/json'},
445
  body: JSON.stringify({message})
@@ -1258,9 +1258,7 @@ function startListening() {
1258
 
1259
  function handleAIResponse(userText) {
1260
  setAvatarState('thinking');
1261
- isSpeakingVoiceLoop = true;
1262
- setVoiceControlButtonsState();
1263
- fetch('http://127.0.0.1:5000/chat', {
1264
  method: 'POST',
1265
  headers: {'Content-Type': 'application/json'},
1266
  body: JSON.stringify({message: userText})
@@ -1270,31 +1268,18 @@ function handleAIResponse(userText) {
1270
  addMessage(data.reply, 'echo');
1271
  setAvatarState('speaking');
1272
  if (characterController && appState.soundEnabled) {
1273
- // استخدم SpeechSynthesisUtterance مع حدث onend
1274
  const utterance = new SpeechSynthesisUtterance(data.reply);
1275
  utterance.lang = 'en-US';
1276
  utterance.onend = () => {
1277
- isSpeakingVoiceLoop = false;
1278
- setAvatarState('idle');
1279
- setVoiceControlButtonsState();
1280
- if (isAutoLoop && !isMuted && isConversationActive) {
1281
- setTimeout(startListening, 500);
1282
- }
1283
- };
1284
- utterance.onerror = () => {
1285
- isSpeakingVoiceLoop = false;
1286
  setAvatarState('idle');
1287
- setVoiceControlButtonsState();
1288
  if (isAutoLoop && !isMuted && isConversationActive) {
1289
  setTimeout(startListening, 500);
1290
  }
1291
  };
1292
  speechSynthesis.speak(utterance);
1293
- characterController.speak(data.reply); // لتحريك الفم
1294
  } else {
1295
- isSpeakingVoiceLoop = false;
1296
  setAvatarState('idle');
1297
- setVoiceControlButtonsState();
1298
  if (isAutoLoop && !isMuted && isConversationActive) {
1299
  setTimeout(startListening, 500);
1300
  }
@@ -1302,9 +1287,7 @@ function handleAIResponse(userText) {
1302
  })
1303
  .catch(() => {
1304
  addMessage("Sorry, I couldn't connect to the AI server.", 'echo');
1305
- isSpeakingVoiceLoop = false;
1306
  setAvatarState('idle');
1307
- setVoiceControlButtonsState();
1308
  if (isAutoLoop && !isMuted && isConversationActive) {
1309
  setTimeout(startListening, 1500);
1310
  }
 
439
  input.value = '';
440
 
441
  // استدعاء الذكاء الاصطناعي عبر الخادم
442
+ fetch('/chat', {
443
  method: 'POST',
444
  headers: {'Content-Type': 'application/json'},
445
  body: JSON.stringify({message})
 
1258
 
1259
  function handleAIResponse(userText) {
1260
  setAvatarState('thinking');
1261
+ fetch('/chat', {
 
 
1262
  method: 'POST',
1263
  headers: {'Content-Type': 'application/json'},
1264
  body: JSON.stringify({message: userText})
 
1268
  addMessage(data.reply, 'echo');
1269
  setAvatarState('speaking');
1270
  if (characterController && appState.soundEnabled) {
 
1271
  const utterance = new SpeechSynthesisUtterance(data.reply);
1272
  utterance.lang = 'en-US';
1273
  utterance.onend = () => {
 
 
 
 
 
 
 
 
 
1274
  setAvatarState('idle');
 
1275
  if (isAutoLoop && !isMuted && isConversationActive) {
1276
  setTimeout(startListening, 500);
1277
  }
1278
  };
1279
  speechSynthesis.speak(utterance);
1280
+ characterController.speak(data.reply);
1281
  } else {
 
1282
  setAvatarState('idle');
 
1283
  if (isAutoLoop && !isMuted && isConversationActive) {
1284
  setTimeout(startListening, 500);
1285
  }
 
1287
  })
1288
  .catch(() => {
1289
  addMessage("Sorry, I couldn't connect to the AI server.", 'echo');
 
1290
  setAvatarState('idle');
 
1291
  if (isAutoLoop && !isMuted && isConversationActive) {
1292
  setTimeout(startListening, 1500);
1293
  }