Search code examples
javascriptgoogle-chromespeech-to-text

Duplicated result returned from Google WebSpeech API


Colleagues, Project is a Bootstrap 3 Form - Text Area with simple Google Chrome Voice to text

Scratching my head - maybe missing something obvious but Javascript is producing a duplicate of text spoken

i.e.; 'this is a testthis is a test'

Any help appreciated.

recognition.onresult = function(event) 
    {
        if (typeof(event.results) == 'undefined') 
        {
        recognition.onend = null;
        recognition.stop();
        return;
        }

        for (var i = event.resultIndex; i < event.results.length; ++i) 
        {
            if (event.results[i].isFinal) 
            {
                $('#Spch2TxtArea').val($('#Spch2TxtArea').val()+event.results[i][0].transcript);
                final_text = 'Y';
            } 
        }
    };

Solution

  • $('#Spch2TxtArea').val(event.results[i][0].transcript);
    

    You had

    ('#Spch2TxtArea').val($('#Spch2TxtArea').val()+event.results[i][0].transcript);
    

    Which means "set the value to that value followed by(+) the transcript