Mycroft Community Forum

Speak/response in loop

Hello, I need some help with ``Speak/response .

I want Mycroft to read me some headlines and ask me after each headline if I want detail or next.
My problem is that Mycroft does not wait for a response, but start to read next headline and stop speaking after two words, wait for response, and continue with speaking.

def is_affirmative(self, utterance, lang='en-us'):

        affirmatives = ['detail', 'yes', 'sure', 'please do']

        for word in affirmatives:

            if word in utterance:

                return True

        return False

    

    def is_next(self, utterance, lang='en-us'):

        affirmatives = ['next', 'continue', 'no', 'nope']

        for word in affirmatives:

            if word in utterance:

                return True

        return False

for i in range(5):

            self.speak(str(entries[i].title),expect_response=False,wait=True)

            response = self.get_response("Detail or next", num_retries=0)

            if response and self.is_affirmative(response):

                self.log.debug("detail")

            if response and self.is_next(response):

                self.log.debug("next")

If I run speak command it wait only few milliseconds.

 09:28:12.159 | DEBUG    | 13003 | NewsSkill | 2020-05-02 09:28:12.159477
 09:28:12.160 | DEBUG    | 13003 | NewsSkill | 2020-05-02 09:28:12.160172

Include this in your program

from mycroft.audio import wait_while_speaking

then before your self.speak line add this

wait_while_speaking()

It is already included in speak command as argument wait=True

I tried to put it before and after command, but it won’t work.

# Loop trought all entries

        time.sleep(2)

        for i in range(4):

            self.log.debug("Start Title "+str(i)+": " + str(datetime.now()))

            self.speak(str(entries[i].title),expect_response=False,wait=True)

            wait_while_speaking()

            self.log.debug("End Title "+str(i)+": " + str(datetime.now()))

            self.log.debug("Count of chars: " + str(len(str(entries[i].title))))

            self.log.debug("Start Question "+str(i)+": " + str(datetime.now()))

            response = self.get_response("Detail?", num_retries=0)

            wait_while_speaking()

            self.log.debug("End Question "+str(i)+" : " + str(datetime.now()))

            if response and self.is_affirmative(response):

                self.log.debug("detail")

                self.log.debug("Start Detail "+str(i)+": " + str(datetime.now()))

                self.speak(str(entries[i].description),expect_response=False,wait=True)

                self.log.debug("End Detail "+str(i)+" : " + str(datetime.now()))

                self.log.debug("Count of chars "+str(i)+": " + str(len(str(entries[i].title))

LOG: https://pastebin.com/SGSCSx83