Nothing fancy yet. When we receive a message through ZeroMQ's PUB/SUB architecture, we tell the robot to say it out loud.
28 lines
618 B
Python
28 lines
618 B
Python
import qi
|
|
import zmq
|
|
import time
|
|
|
|
|
|
def say(session, message):
|
|
tts = session.service("ALTextToSpeech")
|
|
tts.say(message)
|
|
|
|
if __name__ == "__main__":
|
|
app = qi.Application()
|
|
app.start()
|
|
session = app.session
|
|
|
|
context = zmq.Context()
|
|
socket = context.socket(zmq.SUB)
|
|
socket.connect("tcp://localhost:5556")
|
|
socket.setsockopt_string(zmq.SUBSCRIBE, u"") # u because Python 2 shenanigans
|
|
|
|
while True:
|
|
print("Listening for message")
|
|
message = socket.recv_string()
|
|
print("Received message: {}".format(message))
|
|
|
|
say(session, message)
|
|
|
|
time.sleep(1)
|