Spaces:
Running
Running
Update index.html
Browse files- index.html +36 -112
index.html
CHANGED
|
@@ -2,149 +2,73 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<title>
|
| 6 |
<style>
|
| 7 |
-
.
|
| 8 |
max-width: 400px;
|
| 9 |
-
margin:
|
| 10 |
-
padding:
|
| 11 |
border: 1px solid #ccc;
|
| 12 |
-
border-radius:
|
| 13 |
-
box-shadow: 0 0 10px rgba(0,
|
| 14 |
-
font-family:
|
| 15 |
-
}
|
| 16 |
-
.user-message {
|
| 17 |
-
background-color: #f0f0f0;
|
| 18 |
-
border-radius: 5px;
|
| 19 |
-
padding: 5px 10px;
|
| 20 |
-
margin: 5px 0;
|
| 21 |
-
text-align: right;
|
| 22 |
}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
#languageSelector {
|
| 30 |
-
width: 100%;
|
| 31 |
-
margin-top: 10px;
|
| 32 |
-
padding: 5px;
|
| 33 |
border-radius: 5px;
|
| 34 |
-
|
| 35 |
}
|
| 36 |
</style>
|
| 37 |
</head>
|
| 38 |
<body>
|
| 39 |
-
<div class="
|
| 40 |
-
<
|
| 41 |
|
| 42 |
-
<!-- Language
|
| 43 |
<select id="languageSelector">
|
| 44 |
<option value="en-US">English (US)</option>
|
| 45 |
<option value="hi-IN">Hindi (India)</option>
|
| 46 |
-
<option value="es-ES">Spanish
|
| 47 |
-
<option value="fr-FR">French
|
| 48 |
-
<option value="de-DE">German (Germany)</option>
|
| 49 |
-
<option value="ar-SA">Arabic (Saudi Arabia)</option>
|
| 50 |
-
<!-- Add more as needed -->
|
| 51 |
</select>
|
| 52 |
|
| 53 |
-
<
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
</div>
|
| 59 |
</div>
|
| 60 |
|
| 61 |
<script>
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
const action = document.getElementById('action');
|
| 67 |
-
|
| 68 |
-
let recognition = new webkitSpeechRecognition();
|
| 69 |
-
recognition.lang = selectedLang;
|
| 70 |
-
recognition.interimResults = false;
|
| 71 |
recognition.continuous = false;
|
|
|
|
| 72 |
|
| 73 |
recognition.onstart = () => {
|
| 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 |
-
|
| 85 |
};
|
| 86 |
|
| 87 |
-
recognition.
|
| 88 |
-
|
|
|
|
|
|
|
| 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 |
</script>
|
| 149 |
</body>
|
| 150 |
</html>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<title>Speech to Text Demo</title>
|
| 6 |
<style>
|
| 7 |
+
.container {
|
| 8 |
max-width: 400px;
|
| 9 |
+
margin: 30px auto;
|
| 10 |
+
padding: 20px;
|
| 11 |
border: 1px solid #ccc;
|
| 12 |
+
border-radius: 8px;
|
| 13 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
| 14 |
+
font-family: sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
+
#output {
|
| 17 |
+
margin-top: 20px;
|
| 18 |
+
font-size: 18px;
|
| 19 |
+
color: #333;
|
| 20 |
+
background: #f0f0f0;
|
| 21 |
+
padding: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
border-radius: 5px;
|
| 23 |
+
min-height: 40px;
|
| 24 |
}
|
| 25 |
</style>
|
| 26 |
</head>
|
| 27 |
<body>
|
| 28 |
+
<div class="container">
|
| 29 |
+
<h3>Speech to Text</h3>
|
| 30 |
|
| 31 |
+
<!-- Language Selector -->
|
| 32 |
<select id="languageSelector">
|
| 33 |
<option value="en-US">English (US)</option>
|
| 34 |
<option value="hi-IN">Hindi (India)</option>
|
| 35 |
+
<option value="es-ES">Spanish</option>
|
| 36 |
+
<option value="fr-FR">French</option>
|
|
|
|
|
|
|
|
|
|
| 37 |
</select>
|
| 38 |
|
| 39 |
+
<!-- Button to Start Speech -->
|
| 40 |
+
<button onclick="startRecognition()">Tap to Speak</button>
|
| 41 |
+
|
| 42 |
+
<!-- Display Result -->
|
| 43 |
+
<div id="output"></div>
|
|
|
|
| 44 |
</div>
|
| 45 |
|
| 46 |
<script>
|
| 47 |
+
function startRecognition() {
|
| 48 |
+
const lang = document.getElementById('languageSelector').value;
|
| 49 |
+
const output = document.getElementById('output');
|
| 50 |
|
| 51 |
+
const recognition = new webkitSpeechRecognition(); // works in Chrome
|
| 52 |
+
recognition.lang = lang;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
recognition.continuous = false;
|
| 54 |
+
recognition.interimResults = false;
|
| 55 |
|
| 56 |
recognition.onstart = () => {
|
| 57 |
+
output.textContent = "Listening...";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
};
|
| 59 |
|
| 60 |
recognition.onerror = (event) => {
|
| 61 |
+
output.textContent = "Error: " + event.error;
|
| 62 |
};
|
| 63 |
|
| 64 |
+
recognition.onresult = (event) => {
|
| 65 |
+
const transcript = event.results[0][0].transcript;
|
| 66 |
+
output.textContent = transcript;
|
| 67 |
+
console.log("Recognized Text:", transcript); // Print to console
|
| 68 |
};
|
| 69 |
|
| 70 |
recognition.start();
|
| 71 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
</script>
|
| 73 |
</body>
|
| 74 |
</html>
|