Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,12 +12,13 @@ speech_recognition_html = """
|
|
12 |
var recognition = new webkitSpeechRecognition();
|
13 |
recognition.continuous = false; // Stops after speech input
|
14 |
recognition.interimResults = true;
|
15 |
-
|
|
|
16 |
recognition.onresult = function(event) {
|
17 |
var transcript = event.results[event.resultIndex][0].transcript;
|
18 |
document.getElementById('output').textContent = transcript;
|
19 |
// Send transcript back to Streamlit using postMessage
|
20 |
-
window.parent.postMessage(
|
21 |
};
|
22 |
|
23 |
recognition.onerror = function(event) {
|
@@ -26,7 +27,12 @@ speech_recognition_html = """
|
|
26 |
};
|
27 |
|
28 |
function startRecognition() {
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
</script>
|
32 |
</body>
|
@@ -45,8 +51,6 @@ output = st.empty()
|
|
45 |
|
46 |
# The Streamlit component listens for the postMessage event and updates the output
|
47 |
st.write("Recognized Text:")
|
48 |
-
|
49 |
-
# In Streamlit, we capture the transcript message sent via postMessage
|
50 |
transcript = st.text_area("Transcript:", "", height=150)
|
51 |
|
52 |
-
#
|
|
|
12 |
var recognition = new webkitSpeechRecognition();
|
13 |
recognition.continuous = false; // Stops after speech input
|
14 |
recognition.interimResults = true;
|
15 |
+
recognition.lang = "en-US"; // Set the language for recognition
|
16 |
+
|
17 |
recognition.onresult = function(event) {
|
18 |
var transcript = event.results[event.resultIndex][0].transcript;
|
19 |
document.getElementById('output').textContent = transcript;
|
20 |
// Send transcript back to Streamlit using postMessage
|
21 |
+
window.parent.postMessage({func: 'update_output', transcript: transcript}, '*');
|
22 |
};
|
23 |
|
24 |
recognition.onerror = function(event) {
|
|
|
27 |
};
|
28 |
|
29 |
function startRecognition() {
|
30 |
+
try {
|
31 |
+
recognition.start();
|
32 |
+
} catch (error) {
|
33 |
+
console.error("Error starting recognition:", error);
|
34 |
+
document.getElementById('output').textContent = "Error starting recognition";
|
35 |
+
}
|
36 |
}
|
37 |
</script>
|
38 |
</body>
|
|
|
51 |
|
52 |
# The Streamlit component listens for the postMessage event and updates the output
|
53 |
st.write("Recognized Text:")
|
|
|
|
|
54 |
transcript = st.text_area("Transcript:", "", height=150)
|
55 |
|
56 |
+
# JavaScript is sending postMessage with 'update_output' func, you need to listen for this in the frontend
|