35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
if (annyang) {
|
|
const startBtn = document.getElementById('start-record-btn');
|
|
const stopBtn = document.getElementById('stop-record-btn');
|
|
const transcribedText = document.getElementById('transcribed-text');
|
|
|
|
const commands = {
|
|
'*text': (text) => {
|
|
transcribedText.value += text + ' ';
|
|
}
|
|
};
|
|
|
|
annyang.addCommands(commands);
|
|
|
|
startBtn.addEventListener('click', () => {
|
|
transcribedText.value = '';
|
|
annyang.start();
|
|
startBtn.classList.add('d-none');
|
|
stopBtn.classList.remove('d-none');
|
|
});
|
|
|
|
stopBtn.addEventListener('click', () => {
|
|
annyang.abort();
|
|
startBtn.classList.remove('d-none');
|
|
stopBtn.classList.add('d-none');
|
|
});
|
|
|
|
annyang.addCallback('end', function() {
|
|
if (transcribedText.value.trim() === '') {
|
|
transcribedText.value = 'Could not hear anything. Please try again.';
|
|
}
|
|
startBtn.classList.remove('d-none');
|
|
stopBtn.classList.add('d-none');
|
|
});
|
|
|
|
} |