1

In Windows laptop when we press "windows + h". default voice dictate will open. But i want this shortcut button on single Angular button. I want if i click on button that default voice dictate will open instead of pressing windows + h. If anyone have any idea please suggest me.

I am exploring on that functionality but I did not get anything.

Khaled Ayed
  • 1,121
  • 3
  • 12
  • 29

1 Answers1

1

Triggering OS shortcut keys is not possible in a browser as it would be a security risk. I don't think you'll be able to do that exactly.

However there is a related Web Speech API that works in Chrome and Safari. It does not work in all browsers and the experience varies by browser (Safari on Mac uses OS internals, Chrome seems to have its own engine). Here's a generic article on using it: https://12daysofweb.dev/2021/speech-api/

A very-basic use might look like:

function logSpeech() {
  const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
  const recognition = new SR();
  recognition.lang = "en-US";


  recognition.onresult = function (event) {
    const transcript = event.results[0][0].transcript;
    console.log(transcript)
  }

  // in chrome this ends automatically
  recognition.start();
};
tgf
  • 2,977
  • 2
  • 18
  • 29
  • I tried web speech api but that punctuation is not working in Chrome. but its working in Microsoft Edge – swapnil pisal Jun 05 '23 at 05:40
  • I think I know why. Edited with better cross-browser support (`window.webkitSpeechRecognition`). – tgf Jun 05 '23 at 06:19
  • i edited with tinymce editor but still its not working properly that why i shifted to default windows dictation but i am stucking in how to use 'windows + h ' as on single button – swapnil pisal Jun 05 '23 at 07:01
  • I'm not sure you can capture windows key shortcuts. This answer may help you to though: https://stackoverflow.com/questions/7295508/javascript-capture-browser-shortcuts-ctrlt-n-w – tgf Jun 06 '23 at 04:00