Spaces:
Running
Running
Update index.html
Browse files- index.html +17 -87
index.html
CHANGED
@@ -58,93 +58,23 @@
|
|
58 |
</div>
|
59 |
</div>
|
60 |
|
61 |
-
<
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
};
|
76 |
-
|
77 |
-
recognition.onresult = (event) => {
|
78 |
-
var transcript = event.results[0][0].transcript;
|
79 |
-
action.innerHTML = "";
|
80 |
-
sendMessage(transcript);
|
81 |
-
};
|
82 |
-
|
83 |
-
recognition.onerror = (event) => {
|
84 |
-
action.innerHTML = "Error: " + event.error;
|
85 |
-
};
|
86 |
-
|
87 |
-
recognition.onend = () => {
|
88 |
-
action.innerHTML = "";
|
89 |
-
};
|
90 |
-
|
91 |
-
recognition.start();
|
92 |
-
}
|
93 |
-
|
94 |
-
function sendMessage(message) {
|
95 |
-
showUserMessage(message);
|
96 |
-
sendToFlaskAPI(message);
|
97 |
-
}
|
98 |
-
|
99 |
-
function sendToFlaskAPI(message) {
|
100 |
-
fetch('/api/process_text', {
|
101 |
-
method: 'POST',
|
102 |
-
headers: {
|
103 |
-
'Content-Type': 'application/json',
|
104 |
-
},
|
105 |
-
body: JSON.stringify({ text: message })
|
106 |
-
})
|
107 |
-
.then(response => response.json())
|
108 |
-
.then(data => {
|
109 |
-
console.log('Response from Flask API:', data);
|
110 |
-
handleResponse(data);
|
111 |
-
})
|
112 |
-
.catch(error => {
|
113 |
-
console.error('Error sending data to Flask API:', error);
|
114 |
-
});
|
115 |
-
}
|
116 |
-
|
117 |
-
function handleResponse(data) {
|
118 |
-
showBotMessage(data);
|
119 |
-
speakResponse(data);
|
120 |
-
}
|
121 |
-
|
122 |
-
function showUserMessage(message) {
|
123 |
-
var chatBox = document.getElementById('chat-box');
|
124 |
-
var userMessageHTML = '<div class="user-message">' + message + '</div>';
|
125 |
-
chatBox.innerHTML += userMessageHTML;
|
126 |
-
}
|
127 |
-
|
128 |
-
function showBotMessage(message) {
|
129 |
-
var chatBox = document.getElementById('chat-box');
|
130 |
-
var botMessageHTML = '<div class="bot-message">' + message + '</div>';
|
131 |
-
chatBox.innerHTML += botMessageHTML;
|
132 |
-
}
|
133 |
-
|
134 |
-
function speakResponse(response) {
|
135 |
-
var utterance = new SpeechSynthesisUtterance(response);
|
136 |
-
speechSynthesis.speak(utterance);
|
137 |
-
window.addEventListener('beforeunload', function () {
|
138 |
-
if (synth.speaking) {
|
139 |
-
synth.cancel();
|
140 |
-
}
|
141 |
-
});
|
142 |
-
document.getElementById('speech').addEventListener('click', function () {
|
143 |
-
if (synth.speaking) {
|
144 |
-
synth.cancel();
|
145 |
-
}
|
146 |
-
});
|
147 |
}
|
148 |
-
|
|
|
|
|
149 |
</body>
|
150 |
</html>
|
|
|
58 |
</div>
|
59 |
</div>
|
60 |
|
61 |
+
<button onclick="speak()">Speak</button>
|
62 |
+
<script>
|
63 |
+
function speak() {
|
64 |
+
const synth = window.speechSynthesis;
|
65 |
+
const utter = new SpeechSynthesisUtterance("Hello! This is a Safari test.");
|
66 |
+
utter.lang = 'en-US';
|
67 |
+
|
68 |
+
// Wait for voices to be loaded (Safari quirk)
|
69 |
+
const interval = setInterval(() => {
|
70 |
+
const voices = synth.getVoices();
|
71 |
+
if (voices.length > 0) {
|
72 |
+
utter.voice = voices.find(v => v.lang === 'en-US') || voices[0];
|
73 |
+
synth.speak(utter);
|
74 |
+
clearInterval(interval);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
+
}, 100);
|
77 |
+
}
|
78 |
+
</script>
|
79 |
</body>
|
80 |
</html>
|