Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const btn = document.querySelector('.talk');
- const content = document.querySelector('.content');
- const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
- const recognition = new SpeechRecognition();
- recognition.onstart = () => {
- console.log('Sie können nun sprechen!');
- };
- recognition.onresult = (event) => {
- const current = event.resultIndex;
- const transcript = event.results[current][0].transcript;
- content.textContent = transcript;
- speak(transcript);
- //console.log(event);
- };
- btn.addEventListener('click', () => {
- recognition.start();
- });
- function speak(message) {
- const speech = new SpeechSynthesisUtterance();
- speech.volume = 1;
- //speech.lang = 'de-DE';
- speech.rate = 1;
- speech.pitch = 1;
- window.speechSynthesis.speak(speech);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement