mycroft_tts.py
Go to the documentation of this file.
1 # Copyright 2017 Mycroft AI Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 """
16  Mycroft audio service.
17  This handles playback of audio and speech
18 """
19 #!/usr/bin/env python
20 import rospy
21 from std_msgs.msg import String
22 from mycroft.configuration import Configuration
23 from mycroft.messagebus.client.ws import WebsocketClient
24 from mycroft.messagebus.message import Message
25 from mycroft.util import reset_sigint_handler, wait_for_exit_signal, \
26  create_daemon, create_echo_function, check_for_signal
27 from mycroft.util.log import LOG
28 
29 import mycroft.audio.speech as speech
30 from mycroft.audio.audioservice import AudioService
31 
32 bus = None
33 
34 def handle_speak(data):
35  global bus
36  bus.emit(Message('speak', {'utterance': data.data}))
37 
38 def handle_stop(data):
39  global bus
40  bus.emit(Message('mycroft.stop'))
41 
42 def main():
43  rospy.init_node('mycroft_tts')
44  rospy.loginfo(rospy.get_caller_id() + " started")
45  rospy.Subscriber("mycroft/speak", String, handle_speak)
46  rospy.Subscriber("mycroft/stop", String, handle_stop)
47  """ Main function. Run when file is invoked. """
48  global bus
50  check_for_signal("isSpeaking")
51  bus = WebsocketClient() # Connect to the Mycroft Messagebus
52  Configuration.init(bus)
53  speech.init(bus)
54 
55  LOG.info("Starting Audio Services")
56  bus.on('message', create_echo_function('AUDIO', ['mycroft.audio.service']))
57  audio = AudioService(bus) # Connect audio service instance to message bus
58  create_daemon(bus.run_forever)
59 
61 
62  speech.shutdown()
63  audio.shutdown()
64  # keep node running
65  rospy.spin()
66 
67 
68 if __name__ == "__main__":
69  main()
def create_daemon(target, args=(), kwargs=None)
def check_for_signal(signal_name, sec_lifetime=0)
Definition: signal.py:105
def handle_speak(data)
Definition: mycroft_tts.py:34
def create_echo_function(name, whitelist=None)
def main()
Definition: mycroft_tts.py:42
def handle_stop(data)
Definition: mycroft_tts.py:38


mycroft_ros
Author(s):
autogenerated on Mon Apr 26 2021 02:35:40