2017-10-04 06:28:44 +00:00
|
|
|
# Copyright 2017 Mycroft AI Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2017-09-18 19:14:21 +00:00
|
|
|
import time
|
|
|
|
|
2017-10-08 12:10:42 +00:00
|
|
|
from mycroft.util.signal import check_for_signal, create_signal
|
2017-09-18 19:14:21 +00:00
|
|
|
|
2017-06-15 13:50:43 +00:00
|
|
|
|
|
|
|
def is_speaking():
|
|
|
|
"""Determine if Text to Speech is occurring
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True while still speaking
|
|
|
|
"""
|
|
|
|
return check_for_signal("isSpeaking", -1)
|
|
|
|
|
|
|
|
|
|
|
|
def wait_while_speaking():
|
|
|
|
"""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.
|
|
|
|
"""
|
2017-11-22 19:21:23 +00:00
|
|
|
time.sleep(0.3) # Wait briefly in for any queued speech to begin
|
2017-06-15 13:50:43 +00:00
|
|
|
while is_speaking():
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
2017-10-17 11:45:39 +00:00
|
|
|
def stop_speaking():
|
2017-06-15 13:50:43 +00:00
|
|
|
# TODO: Less hacky approach to this once Audio Manager is implemented
|
|
|
|
# Skills should only be able to stop speech they've initiated
|
2017-10-17 11:45:39 +00:00
|
|
|
from mycroft.messagebus.send import send
|
2017-06-15 13:50:43 +00:00
|
|
|
create_signal('stoppingTTS')
|
2017-10-17 11:45:39 +00:00
|
|
|
send('mycroft.audio.speech.stop')
|
2017-06-15 13:50:43 +00:00
|
|
|
|
2017-10-08 19:03:02 +00:00
|
|
|
# Block until stopped
|
2017-06-15 13:50:43 +00:00
|
|
|
while check_for_signal("isSpeaking", -1):
|
|
|
|
time.sleep(0.25)
|
|
|
|
|
|
|
|
# This consumes the signal
|
|
|
|
check_for_signal('stoppingTTS')
|