-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
43 lines (39 loc) · 1.69 KB
/
preload.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
38
39
40
41
42
43
const { ipcRenderer } = require('electron');
window.addEventListener('DOMContentLoaded', () => {
const transcriptionText = document.getElementById('transcription-text');
const soundwaveContainer = document.getElementById('soundwave-container');
let mediaRecorder;
let chunks = [];
ipcRenderer.on('toggle-playback-mode', (event, isPlaying) => {
if (isPlaying) {
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = event => {
chunks.push(event.data);
const reader = new FileReader();
reader.onload = () => {
const transcript = reader.result;
ipcRenderer.send('transcription-update', transcript);
};
reader.readAsText(event.data);
};
mediaRecorder.start();
})
.catch(err => {
console.error('Error accessing microphone:', err);
});
} else if (mediaRecorder) {
mediaRecorder.stop();
mediaRecorder = null;
chunks = [];
}
});
ipcRenderer.on('transcription-update', (event, transcript) => {
transcriptionText.textContent += ` ${transcript}`;
});
ipcRenderer.on('mic-permission-status', (event, status) => {
const micStatus = status ? 'Microphone Permissions: ON' : 'Microphone Permissions: OFF';
document.getElementById('mic-status').textContent = micStatus;
});
});