forgottofly forgottofly - 1 year ago 151
Android Question

Ionic app not recognizing speech in android mobile

I wanted to design an ionic app that listens to voice commands by following the tutorial here
But the app seems to recognize the voice commands over the microphone if tested on my computer using the

var recognition = new webkitSpeechRecognition(); //To Computer
command.But on seeing this post I replaced the command to

var recognition = new SpeechRecognition(); // To Device

But this dosen't seem to work on my android device..
Has anybody faced the same issue with SpeechRecognitionPlugin ?
Please share your thoughts and reviews...Thanks

Answer Source

Finally able to crack it. The trick was to add the cordova media plugin.

The working code is as follows:


<!DOCTYPE html>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Speech Recognition</title>
        Click to speak <input type="button" value="speak" name="Download" id="speak" />  <br>
        <input type="text" id="q" name="q" size=60>

        <script type="text/javascript" src="js/jquery.js"></script> 
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/app.js"></script>


$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);

var recognition;
function onDeviceReady() {  

    $('#speak').click( function() {
        recognition = new SpeechRecognition();          
        recognition.onresult = function(event) {
            if (event.results.length > 0) {
                q.value = event.results[0][0].transcript;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download