speech recognition + microphone level

753 views
Skip to first unread message

toma...@stinkdigital.com

unread,
Apr 22, 2013, 6:53:03 AM4/22/13
to chromiu...@chromium.org
hi everyone

wondering if anyone has ever tried making webkitSpeechRecognition and webkitAudioContext work together?

the basic idea is to have the speech recognition work and show a mic level meter on the page at the same time.

my sample code kind of works, but it asks to access the microphone twice, while my idea is to connect the level checker to the existing context

any suggestion appreciated, thanks!
thomas

var that = this;
var recognition = new webkitSpeechRecognition();

recognition.continuous = true;
recognition.interimResults = true;

recognition.onstart = function() 
{
var context = new webkitAudioContext();  
navigator.webkitGetUserMedia(
{
audio: true
}, 
function(stream) 
{
var liveSource = context.createMediaStreamSource(stream);
var levelChecker = context.createJavaScriptNode(1024, 1 ,1);

liveSource.connect(levelChecker);
levelChecker.connect(context.destination);
levelChecker.onaudioprocess = that.processAudio;
}
);
that.isRunning(true);
};

Basharat Choudhry

unread,
Jun 16, 2013, 3:43:15 AM6/16/13
to chromiu...@chromium.org
Hi Thomas-

I've been curious about getting these two features to work together as well.
It's a bit buggy, but here is a link to some code that got me close, but not all the way:

It works for integrated mic arrays very well.
However, I can't get it working for normal, mono mics.
Of course, unless you're using https, it will ask you for permission every time you go over 50.

Thomas Alisi

unread,
Jun 17, 2013, 4:29:47 AM6/17/13
to chromiu...@chromium.org
hey

that's cool. what's the reason behind using the context analyser instead of directly accessing the audio buffer?

I implemented this little snippet and works just fine, tested on a wide range of laptop / desktop microphones. what I'd really like is to find a way of reattaching the stream to the existing audio context, this should hopefully request for authorization only once? thing is the webspeech api doesn't seem to expose the audio context, hence the need of instantiating a new one...

navigator.webkitGetUserMedia(
{
audio: true
}, 
function(stream) 
{
// "that" is my wrapping object's scope
that.stream = stream;

var liveSource = context.createMediaStreamSource(stream);
var levelChecker = context.createJavaScriptNode(that.bufSize, 1 ,1);

liveSource.connect(levelChecker);
levelChecker.connect(context.destination);
levelChecker.onaudioprocess = function(event) 
{
var buf = event.inputBuffer.getChannelData(0);
var len = buf.length;
var rms = 0;

// Iterate through buffer
for (var i = 0; i < len; i++) 
{
rms += Math.abs(buf[i]);
}
rms = Math.sqrt(rms / len);
that.levelCheckerCB(rms);
};
}
);

Bash

unread,
Jun 17, 2013, 1:02:49 PM6/17/13
to Thomas Alisi, chromiu...@chromium.org
I was using the analyser because I was running into issues connecting directly to the JavaScriptNode. It would record levels for a short period of time and then stop. Adding the analyser made it run indefinitely for some reason. Currently I can't find a way around asking for permission twice. I'll look into this snippit you have here. Does it replace your previous snippit's navigator.webkitGetUserMedia?

- Choudhry, Basharat "Bash"


--
You received this message because you are subscribed to a topic in the Google Groups "Chromium HTML5" group.
To unsubscribe from this topic, visit https://groups.google.com/a/chromium.org/d/topic/chromium-html5/AidRiQbJ1Kg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to chromium-html...@chromium.org.
To post to this group, send email to chromiu...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/.
For more options, visit https://groups.google.com/a/chromium.org/groups/opt_out.
 
 

Bash

unread,
Jun 17, 2013, 1:28:40 PM6/17/13
to Thomas Alisi, chromiu...@chromium.org
yep. still pulling in zeroes even with your snippet.
I haven't check on my mic array machine yet, which is the only one that usually shows levels.
I think I've got a completely different problem. Only other place I've seen it mentioned is here:

- Choudhry, Basharat "Bash"

Basharat Choudhry

unread,
Jun 17, 2013, 1:55:11 PM6/17/13
to chromiu...@chromium.org, Thomas Alisi
Sorry for the frequent replies. I figured out my zero levels issue from this issue thread:

It had to do with the sample rates matching for input and output.
Now I can go back to looking at getting just one mic authorization somehow.

jh.w...@gmail.com

unread,
Feb 5, 2014, 9:48:47 AM2/5/14
to chromiu...@chromium.org, Thomas Alisi, mailba...@gmail.com
Hi Basharat,

did you manage to find a solution for granting permission twice? I ran into the same problem today but could not find a workaround.

Thanks,
Jan

Basharat Choudhry

unread,
Feb 5, 2014, 10:20:20 AM2/5/14
to chromiu...@chromium.org, Thomas Alisi, mailba...@gmail.com
Installing SSL and asking over https somewhat helps.
You will be asked twice as usual.
However, once you answer "Yes" to both, you will not be prompted again.
Reply all
Reply to author
Forward
0 new messages