Chaitanya895 commited on
Commit
2987e5b
·
verified ·
1 Parent(s): 6c0aee9

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +16 -0
templates/index.html CHANGED
@@ -97,6 +97,22 @@
97
  }
98
  chat.appendChild(botRow);
99
  chat.scrollTop = chat.scrollHeight;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  })
101
  .catch(error => {
102
  chat.removeChild(botTypingRow);
 
97
  }
98
  chat.appendChild(botRow);
99
  chat.scrollTop = chat.scrollHeight;
100
+ // Request TTS for the bot response and play it
101
+ try {
102
+ fetch('/text_to_speech', {
103
+ method: 'POST',
104
+ headers: { 'Content-Type': 'application/json' },
105
+ body: JSON.stringify({ text: data.response, lang: 'auto' })
106
+ })
107
+ .then(r => r.json())
108
+ .then(t => {
109
+ if (t && t.tts_url) {
110
+ const audio = new Audio(t.tts_url);
111
+ audio.play().catch(()=>{});
112
+ }
113
+ })
114
+ .catch(()=>{});
115
+ } catch(e){}
116
  })
117
  .catch(error => {
118
  chat.removeChild(botTypingRow);