Advertisement
Guest User

speechRecog

a guest
Dec 11th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const btn = document.querySelector('.talk');
  2. const content = document.querySelector('.content');
  3.  
  4. const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
  5. const recognition = new SpeechRecognition();
  6.  
  7. recognition.onstart = () => {
  8.     console.log('Sie können nun sprechen!');
  9. };
  10.  
  11. recognition.onresult = (event) => {
  12.     const current = event.resultIndex;
  13.     const transcript = event.results[current][0].transcript;
  14.     content.textContent = transcript;
  15.     speak(transcript);
  16.     //console.log(event);
  17. };
  18.  
  19. btn.addEventListener('click', () => {
  20.     recognition.start();
  21. });
  22.  
  23. function speak(message) {
  24.     const speech = new SpeechSynthesisUtterance();
  25.     speech.volume = 1;
  26.     //speech.lang = 'de-DE';
  27.     speech.rate = 1;
  28.     speech.pitch = 1;
  29.     window.speechSynthesis.speak(speech);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement