Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,33 +39,25 @@ def home():
|
|
| 39 |
<label for="username">Username:</label>
|
| 40 |
<input type="text" id="username" placeholder="Enter your username">
|
| 41 |
</div>
|
| 42 |
-
|
| 43 |
<div id="transcription" style="border: 1px solid #ccc; padding: 10px; margin-top: 5px; min-height: 50px;"></div>
|
| 44 |
<script>
|
| 45 |
// Check for browser support
|
| 46 |
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 47 |
-
|
| 48 |
if (!window.SpeechRecognition) {
|
| 49 |
alert("Your browser does not support Speech Recognition. Try Google Chrome.");
|
| 50 |
}
|
| 51 |
-
|
| 52 |
let recognition = new window.SpeechRecognition();
|
| 53 |
recognition.continuous = true; // Keep listening even after getting a result
|
| 54 |
recognition.interimResults = true; // Show interim results
|
| 55 |
let liveOutput = document.getElementById('transcription');
|
| 56 |
-
|
| 57 |
let lastTranscription = '';
|
| 58 |
let intervalId = null;
|
| 59 |
-
|
| 60 |
recognition.onresult = (event) => {
|
| 61 |
let currentTranscription = '';
|
| 62 |
-
|
| 63 |
// Concatenate all the transcriptions
|
| 64 |
for (const result of event.results) {
|
| 65 |
currentTranscription += result[0].transcript;
|
| 66 |
}
|
| 67 |
-
|
| 68 |
-
|
| 69 |
liveOutput.textContent = currentTranscription;
|
| 70 |
|
| 71 |
// Check if there's a new transcription
|
|
@@ -74,11 +66,9 @@ def home():
|
|
| 74 |
console.log(currentTranscription);
|
| 75 |
}
|
| 76 |
};
|
| 77 |
-
|
| 78 |
recognition.onerror = (event) => {
|
| 79 |
console.error('Speech recognition error', event.error);
|
| 80 |
};
|
| 81 |
-
|
| 82 |
function sendTranscriptionToServer(transcription) {
|
| 83 |
let username = document.getElementById('username').value;
|
| 84 |
$.ajax({
|
|
@@ -94,20 +84,22 @@ def home():
|
|
| 94 |
}
|
| 95 |
});
|
| 96 |
}
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
// Start and stop functions
|
| 99 |
document.getElementById('start').addEventListener('click', () => {
|
| 100 |
recognition.start();
|
| 101 |
intervalId = setInterval(() => sendTranscriptionToServer(lastTranscription), 600);
|
|
|
|
| 102 |
});
|
| 103 |
-
|
| 104 |
document.getElementById('stop').addEventListener('click', () => {
|
| 105 |
recognition.stop();
|
| 106 |
clearInterval(intervalId);
|
| 107 |
});
|
| 108 |
</script>
|
| 109 |
-
|
| 110 |
-
|
| 111 |
</body></html>
|
| 112 |
"""
|
| 113 |
return Response(html_content, mimetype='text/html')
|
|
|
|
| 39 |
<label for="username">Username:</label>
|
| 40 |
<input type="text" id="username" placeholder="Enter your username">
|
| 41 |
</div>
|
|
|
|
| 42 |
<div id="transcription" style="border: 1px solid #ccc; padding: 10px; margin-top: 5px; min-height: 50px;"></div>
|
| 43 |
<script>
|
| 44 |
// Check for browser support
|
| 45 |
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
|
|
| 46 |
if (!window.SpeechRecognition) {
|
| 47 |
alert("Your browser does not support Speech Recognition. Try Google Chrome.");
|
| 48 |
}
|
|
|
|
| 49 |
let recognition = new window.SpeechRecognition();
|
| 50 |
recognition.continuous = true; // Keep listening even after getting a result
|
| 51 |
recognition.interimResults = true; // Show interim results
|
| 52 |
let liveOutput = document.getElementById('transcription');
|
|
|
|
| 53 |
let lastTranscription = '';
|
| 54 |
let intervalId = null;
|
|
|
|
| 55 |
recognition.onresult = (event) => {
|
| 56 |
let currentTranscription = '';
|
|
|
|
| 57 |
// Concatenate all the transcriptions
|
| 58 |
for (const result of event.results) {
|
| 59 |
currentTranscription += result[0].transcript;
|
| 60 |
}
|
|
|
|
|
|
|
| 61 |
liveOutput.textContent = currentTranscription;
|
| 62 |
|
| 63 |
// Check if there's a new transcription
|
|
|
|
| 66 |
console.log(currentTranscription);
|
| 67 |
}
|
| 68 |
};
|
|
|
|
| 69 |
recognition.onerror = (event) => {
|
| 70 |
console.error('Speech recognition error', event.error);
|
| 71 |
};
|
|
|
|
| 72 |
function sendTranscriptionToServer(transcription) {
|
| 73 |
let username = document.getElementById('username').value;
|
| 74 |
$.ajax({
|
|
|
|
| 84 |
}
|
| 85 |
});
|
| 86 |
}
|
| 87 |
+
|
| 88 |
+
function clearTranscription() {
|
| 89 |
+
liveOutput.textContent = '';
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
// Start and stop functions
|
| 93 |
document.getElementById('start').addEventListener('click', () => {
|
| 94 |
recognition.start();
|
| 95 |
intervalId = setInterval(() => sendTranscriptionToServer(lastTranscription), 600);
|
| 96 |
+
setInterval(clearTranscription, 2000); // Clear transcription every 2 seconds
|
| 97 |
});
|
|
|
|
| 98 |
document.getElementById('stop').addEventListener('click', () => {
|
| 99 |
recognition.stop();
|
| 100 |
clearInterval(intervalId);
|
| 101 |
});
|
| 102 |
</script>
|
|
|
|
|
|
|
| 103 |
</body></html>
|
| 104 |
"""
|
| 105 |
return Response(html_content, mimetype='text/html')
|