Mycroft Community Forum

Check if message is being emitted

Hi,

Essentially, we’re developing a project of which part is Mycroft talking to itself.
(catching its own utterances and then sort of ‘expanding’ on them.

For the moment, we’re putting simple delays between utterances which gets cloggy quite fast.

I was wondering if there’s a way to check if mycroft is currently saying something (i.e. if message.isEmitting(), not simply catching the message on the bus as that does not indicate how long Mycroft will actually take to speak it out), or somehow calculate the length in order to get the timings right?

Thanks.

The voice is pulseaudio by default with a stream name. Forget exact name its in mycroft.conf after paplay (mycroft-voice or something).
I don’t really know as don’t do much python or even looked at the python pulseaudio modules but at a guess you can check for that stream via python portaudio/PyAudio or the pulseaudio dbus.

There is a wait_while_speaking() function that pause as long as mycroft is speaking. Maybe you could use that ?

wait_while_speaking

mycroft.util. wait_while_speaking ()[source]

Pause as long as Text to Speech is still happening

Pause while Text to Speech is still happening. This always pauses briefly to ensure that any preceeding request to speak has time to begin.

1 Like

when we’re at espeak it doesn’t work

Ah, this will teach me yet another lesson on how to read the documentation carefully. Thanks!

Thanks for this. the integrated function proposed by @andlo will most likely do the trick, but your option is also good if we wander beyond mycroft’s internal utterances and incorporate sounds from elsewhere.

It would be best if sound from elsewhere did let mycroft know that “elsewhere” is using the speaker, and also give mycroft a way to stop it if needed - like an alarm or an anouncement. If Mycroft knows that “elsewhere” is using the speaker he could also show that on the screen.
So I would alway prefear that on my smartspeaker mycroft were in control - so a skill would be the one playig the sound from elsewhere would be the right way to go in my opinion…

Apparently,
mycroft.utils.wait_while_speaking() is depreciated, use mycroft.audio.wait_while_speaking() instead.

2 Likes