Auto commit: 2025-10-14T13:34:39.654Z
This commit is contained in:
parent
c6bb8383dc
commit
0853753dc1
@ -154,4 +154,9 @@ body {
|
||||
40% {
|
||||
transform: scale(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#speech-to-text-btn.listening {
|
||||
background-color: #dc3545;
|
||||
border-color: #dc3545;
|
||||
}
|
||||
|
||||
@ -88,4 +88,48 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const speechToTextButton = document.getElementById('speech-to-text-btn');
|
||||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||||
|
||||
if (SpeechRecognition) {
|
||||
const recognition = new SpeechRecognition();
|
||||
recognition.continuous = false;
|
||||
recognition.lang = 'en-US';
|
||||
recognition.interimResults = false;
|
||||
recognition.maxAlternatives = 1;
|
||||
|
||||
speechToTextButton.addEventListener('click', () => {
|
||||
recognition.start();
|
||||
speechToTextButton.classList.add('listening');
|
||||
speechToTextButton.disabled = true;
|
||||
});
|
||||
|
||||
recognition.onresult = (event) => {
|
||||
const transcript = event.results[0][0].transcript;
|
||||
messageInput.value = transcript;
|
||||
};
|
||||
|
||||
recognition.onspeechend = () => {
|
||||
recognition.stop();
|
||||
};
|
||||
|
||||
recognition.onend = () => {
|
||||
speechToTextButton.classList.remove('listening');
|
||||
speechToTextButton.disabled = false;
|
||||
};
|
||||
|
||||
recognition.onerror = (event) => {
|
||||
console.error('Speech recognition error:', event.error);
|
||||
alert(`Error occurred in speech recognition: ${event.error}`);
|
||||
speechToTextButton.classList.remove('listening');
|
||||
speechToTextButton.disabled = false;
|
||||
};
|
||||
} else {
|
||||
if (speechToTextButton) {
|
||||
speechToTextButton.style.display = 'none';
|
||||
}
|
||||
console.log('Speech Recognition not supported in this browser.');
|
||||
alert('Speech Recognition not supported in this browser.');
|
||||
}
|
||||
});
|
||||
|
||||
@ -68,6 +68,9 @@
|
||||
</div>
|
||||
<div class="chat-footer">
|
||||
<input type="text" class="form-control" placeholder="Type a message...">
|
||||
<button class="btn btn-secondary" id="speech-to-text-btn">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-mic"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="22"></line></svg>
|
||||
</button>
|
||||
<button class="btn btn-primary">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user