TalAter / annyang

:speech_balloon: Speech recognition for your site
https://www.talater.com/annyang/
MIT License
6.57k stars 1.05k forks source link

Use annyang in chrome extension #432

Open realrecordzLab opened 3 years ago

realrecordzLab commented 3 years ago

Is possible to integrate this inside a google chrome extension? I've Installed the library using npm and I'm using it inside the background script but it seems not working?

import annyang from 'annyang';

annyang.setLanguage('it-IT');

const commands = {
  'Chrome go to *site': openWebsite
}

const openWebsite = (site) => {
  console.log(site);
}

annyang.addCommands(commands);

chrome.browserAction.onClicked.addListener( (activeTab) => {
  console.log(activeTab);

  annyang.start({autoRestart: false, continuous: false });
  annyang.addCallback('start', (e) => {
    console.log(e);
  });
  //chrome.tabs.update();
});
ndcg91 commented 2 years ago

You can load the annoying.min.js inside the webpage that gets affected by the extension and run your commands from there

const annyangScript = document.createElement('script'); annyangScript.setAttribute("type", "module"); annyangScript.setAttribute("src", chrome.runtime.getURL('js/managers/voiceManager/annyang.min.js')); const annyangScriptHead = document.head || document.getElementsByTagName("head")[0] || document.documentElement; head.insertBefore(annyangScript, annyangScriptHead.firstChild);