0

The speak function in web speech in java script doesn't work inside foreach loop ?

if(com1[0]=="timeline")
{

$(function(){

$.ajax({
    url: 'get_tweets.php',
    type: 'GET',
    success: function(response) {

        if (typeof response.errors === 'undefined' || response.errors.length < 1) {

            var $tweets = $('<p></p>');
            $.each(response, function(i, obj) {

             var result="say next tweet ";
                             var msg = new SpeechSynthesisUtterance(result);
                             synth.speak(msg);  

              alert(i);
                $tweets.append('tweet' +'<br>' + obj.text + '<br>');
                $('.tweets-container').html($tweets);

            });
        } 
CMedina
  • 4,034
  • 3
  • 24
  • 39
  • You will probably need to wait for the speak method to return. I would bet that it is an async method. You might need to see if there is a callback method you can use to start the next speak call. – Nicholas Robinson Jun 28 '16 at 15:35
  • speak() does not take a callback. 'The speak() method of the SpeechSynthesis interface adds an utterance to the utterance queue; it will be spoken when any other utterances queued before it have been spoken.' – bhspencer Jun 28 '16 at 15:59
  • I can use synth.speak in a for loop. Are you certain you are calling it more than once? – bhspencer Jun 28 '16 at 16:02

0 Answers0