Use annyang in chrome extension
realrecordzLab opened this issue · 1 comments
realrecordzLab commented
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
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);