-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
158 lines (138 loc) · 5.67 KB
/
app.js
File metadata and controls
158 lines (138 loc) · 5.67 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
document.addEventListener('DOMContentLoaded', function() {
// Initialize emailjs if needed
// emailjs.init("YOUR_USER_ID");
let isRecording = false;
// Upload audio file
document.getElementById('upload-audio').addEventListener('change', function(event) {
const audioFile = event.target.files[0];
if (!audioFile) {
alert('Please select an audio file.');
return;
}
const formData = new FormData();
formData.append('audio_file', audioFile);
const spinner = document.getElementById('loading-spinner');
spinner.style.display = 'block';
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', function(event) {
const response = JSON.parse(xhr.responseText);
updateOutput(response);
spinner.style.display = 'none';
});
xhr.addEventListener('error', function(event) {
console.error('Error uploading file');
spinner.style.display = 'none';
});
xhr.open('POST', '/transcribe');
xhr.send(formData);
});
// Start/Stop recording
document.getElementById('start-recording').addEventListener('click', function() {
console.log('Start recording button clicked');
if (!isRecording) {
startRecording();
} else {
stopRecording();
}
});
function startRecording() {
console.log('Starting recording...');
isRecording = true;
document.getElementById('start-recording').innerText = 'Stop Recording';
document.getElementById('mic-icon').style.display = 'inline-block';
document.getElementById('loading-spinner').style.display = 'none';
fetch('/recognize_continuous_async', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ action: 'start' })
}).then(response => {
console.log('Start recording response received');
if (!response.ok) {
throw new Error('Failed to start recording');
}
}).catch(error => {
console.error('Error:', error);
alert('Error starting recording: ' + error.message);
});
}
function stopRecording() {
console.log('Stopping recording...');
isRecording = false;
document.getElementById('start-recording').innerText = 'Start Recording';
document.getElementById('mic-icon').style.display = 'none';
document.getElementById('loading-spinner').style.display = 'block';
fetch('/recognize_continuous_async', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ action: 'stop' })
}).then(response => response.json()).then(data => {
console.log('Stop recording response received', data);
if (data.transcript) {
updateOutput(data);
} else if (data.error) {
console.error('Error:', data.error);
alert('Error stopping recording: ' + data.error);
document.getElementById('loading-spinner').style.display = 'none';
} else {
console.error('No transcript available');
document.getElementById('loading-spinner').style.display = 'none';
}
}).catch(error => {
console.error('Error:', error);
alert('Error stopping recording: ' + error.message);
document.getElementById('loading-spinner').style.display = 'none';
});
}
function updateOutput(data) {
if (data.transcript) {
document.getElementById('transcript-text').innerText = data.transcript;
}
if (data.summary) {
document.getElementById('summary-text').innerText = data.summary;
}
if (data.insights) {
document.getElementById('insights-text').innerText = data.insights;
}
document.getElementById('input-screen').style.display = 'none';
document.getElementById('output-screen').style.display = 'block';
document.getElementById('loading-spinner').style.display = 'none';
}
// Send email
document.getElementById('send-email').addEventListener('click', function() {
const email = document.getElementById('email-input').value;
const transcript = document.getElementById('transcript-text').innerText;
const summary = document.getElementById('summary-text').innerText;
const insights = document.getElementById('insights-text').innerText;
if (!email || !transcript || !summary || !insights) {
alert('All fields are required');
return;
}
const data = {
email: email,
transcript: transcript,
summary: summary,
insights: insights
};
fetch('/send_email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => response.json()).then(data => {
if (data.error) {
alert('Error: ' + data.error);
} else {
alert('Email sent successfully!');
}
}).catch(error => {
console.error('Error:', error);
});
});
// Additional logging for troubleshooting
console.log('DOM fully loaded and parsed');
});