2 Replies Latest reply on Sep 17, 2018 10:35 PM by Shrey Jain

    How to make voice recognition enable on phone/mobile??

    Shrey Jain

      I am using a Web speech recognition API in tableau to control the tableau Dashboards via voice commands. Voice recognition perfectly work on web. but on mobile it is not working.this API is unable to read my voice on Mobile devices. I don't get the Use Microphone Pop-Up on mobile while using this API,Please find the screenshot below:

       

       

      this is my code:

       

       

       

      var webaudio_tooling_obj = function () {

       

       

          var audioContext = new AudioContext();

       

       

          console.log("audio is starting up ...");

       

       

          var BUFF_SIZE = 16384;

       

       

          var audioInput = null,

              microphone_stream = null,

              gain_node = null,

              script_processor_node = null,

              script_processor_fft_node = null,

              analyserNode = null;

       

       

          if (!navigator.getUserMedia)

                  navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||

                                navigator.mozGetUserMedia || navigator.msGetUserMedia;

       

       

         

          if (navigator.getUserMedia){

       

       

              navigator.getUserMedia({audio:true},

                function(stream) {

                    start_microphone(stream);

                },

                function(e) {

                  alert('Error capturing audio.');

                }

              );

       

       

          } else { alert('getUserMedia not supported in this browser.'); }

       

       

          // ---

       

       

          function show_some_data(given_typed_array, num_row_to_display, label) {

       

       

              var size_buffer = given_typed_array.length;

              var index = 0;

              var max_index = num_row_to_display;

       

       

              console.log("__________ " + label);

       

       

              for (; index < max_index && index < size_buffer; index += 1) {

       

       

                  console.log(given_typed_array[index]);

              }

          }

       

       

          function process_microphone_buffer(event) {

       

       

              var i, N, inp, microphone_output_buffer;

       

       

              microphone_output_buffer = event.inputBuffer.getChannelData(0); // just mono - 1 channel for now

       

       

              // microphone_output_buffer  <-- this buffer contains current gulp of data size BUFF_SIZE

       

       

              show_some_data(microphone_output_buffer, 5, "from getChannelData");

          }

       

       

          function start_microphone(stream){

       

       

            gain_node = audioContext.createGain();

            gain_node.connect( audioContext.destination );

       

       

            microphone_stream = audioContext.createMediaStreamSource(stream);

            microphone_stream.connect(gain_node);

       

       

            script_processor_node = audioContext.createScriptProcessor(BUFF_SIZE, 1, 1);

            script_processor_node.onaudioprocess = process_microphone_buffer;

       

       

            microphone_stream.connect(script_processor_node);

       

       

           

       

       

            // --- setup FFT

       

       

            script_processor_fft_node = audioContext.createScriptProcessor(2048, 1, 1);

            script_processor_fft_node.connect(gain_node);

       

       

            analyserNode = audioContext.createAnalyser();

            analyserNode.smoothingTimeConstant = 0;

            analyserNode.fftSize = 2048;

       

       

            microphone_stream.connect(analyserNode);

       

       

            analyserNode.connect(script_processor_fft_node);

       

       

            script_processor_fft_node.onaudioprocess = function() {

       

       

              // get the average for the first channel

              var array = new Uint8Array(analyserNode.frequencyBinCount);

              analyserNode.getByteFrequencyData(array);

       

       

              // draw the spectrogram

              if (microphone_stream.playbackState == microphone_stream.PLAYING_STATE) {

       

       

                  show_some_data(array, 5, "from fft");

              }

            };

          }

       

       

        }();

      ----------------------------------------
      Also in js file i have used this:

       

      try {

        var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;

        var recognition = new SpeechRecognition();

        recognition.continuous=true;

      }

      catch(e) {

        // console.error(e);

        $('.no-browser-support').show();

        //$('.app').hide();

      }