p5.speechrec not working for chrome popup and background

I am using p5.speech for my chrome extension if i include all the files in content_scripts, it works fine on page load. But on including it in my popup.html or background_scripts, p5 speech is working but speechrec doesnt seem to work. (1)Using in background script



var lang = navigator.language || 'en-US';
var speechrec= new p5.SpeechRec(lang,gotSpeech);
var cont = true;
var interm = false;

var foo = new p5.Speech();

function gotSpeech(){

In this case it says hello when i start browser and even in the background page console it shows p5 speech loaded but speechrec doesn't work.

(2)i included same scripts in popup.html similar result for popup, when i click extension icon it opens the popup and says hello but doesn't listen to anything.

Only including these in content scripts js makes the speech recognition work on load of each tab.

PS: i get a warning about chrome starting the audio policy again in Oct 2018 in console but i get them every time i use p5.speech even when it is working.