-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (35 loc) · 1.52 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
document.addEventListener("DOMContentLoaded", function() {
let transcription = ''; // Variable to store the transcribed text
// Event listener for the Record button
document.getElementById('recordBtn').addEventListener('click', function() {
fetch('/record_audio', { method: 'POST' })
.then(response => response.json())
.then(data => {
if (data.partial_text) {
transcription += data.partial_text + ' '; // Append partial text to transcription
document.getElementById('status').innerText = transcription;
}
})
.catch(error => console.error('Error:', error));
});
// Event listener for the Finish button
document.getElementById('finishBtn').addEventListener('click', function() {
fetch('/translate_and_speak', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // Set the content type to JSON
},
body: JSON.stringify({ 'transcribed_text': transcription })
})
.then(response => response.json())
.then(data => {
console.log(data); // Check the response data in the console
if (data.message) {
document.getElementById('status').innerText = data.message;
} else if (data.error) {
document.getElementById('status').innerText = data.error;
}
})
.catch(error => console.error('Error:', error));
});
});