Skip to content

Commit

Permalink
VIC-5166 Move say_text from robot to behavior (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
msintov committed Apr 30, 2019
1 parent ee0b6cc commit 6001b30
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
23 changes: 23 additions & 0 deletions anki_vector/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,29 @@ async def drive_on_charger(self):
drive_on_charger_request = protocol.DriveOnChargerRequest()
return await self.grpc_interface.DriveOnCharger(drive_on_charger_request)

@connection.on_connection_thread()
async def say_text(self, text: str, use_vector_voice: bool = True, duration_scalar: float = 1.0) -> protocol.SayTextResponse:
"""Make Vector speak text.
.. testcode::
import anki_vector
with anki_vector.Robot() as robot:
robot.behavior.say_text("Hello World")
:param text: The words for Vector to say.
:param use_vector_voice: Whether to use Vector's robot voice
(otherwise, he uses a generic human male voice).
:param duration_scalar: Adjust the relative duration of the
generated text to speech audio.
:return: object that provides the status and utterance state
"""
say_text_request = protocol.SayTextRequest(text=text,
use_vector_voice=use_vector_voice,
duration_scalar=duration_scalar)
return await self.conn.grpc_interface.SayText(say_text_request)

@connection.on_connection_thread()
async def set_eye_color(self, hue: float, saturation: float) -> protocol.SetEyeColorResponse:
"""Set Vector's eye color.
Expand Down
4 changes: 2 additions & 2 deletions anki_vector/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def on_robot_observed_face(robot, event_type, event):
global said_text
if not said_text:
said_text = True
robot.say_text("I see a face!")
robot.behavior.say_text("I see a face!")
evt.set()
args = anki_vector.util.parse_command_args()
Expand Down Expand Up @@ -358,7 +358,7 @@ def on_robot_observed_face(robot, event_type, event):
global said_text
if not said_text:
said_text = True
robot.say_text("I see a face!")
robot.behavior.say_text("I see a face!")
evt.set()
args = anki_vector.util.parse_command_args()
Expand Down
27 changes: 2 additions & 25 deletions anki_vector/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,29 +829,6 @@ async def get_network_state(self) -> protocol.NetworkStateResponse:
get_network_state_request = protocol.NetworkStateRequest()
return await self.conn.grpc_interface.NetworkState(get_network_state_request)

@connection.on_connection_thread()
async def say_text(self, text: str, use_vector_voice: bool = True, duration_scalar: float = 1.0) -> protocol.SayTextResponse:
"""Make Vector speak text.
.. testcode::
import anki_vector
with anki_vector.Robot() as robot:
robot.say_text("Hello World")
:param text: The words for Vector to say.
:param use_vector_voice: Whether to use Vector's robot voice
(otherwise, he uses a generic human male voice).
:param duration_scalar: Adjust the relative duration of the
generated text to speech audio.
:return: object that provides the status and utterance state
"""
say_text_request = protocol.SayTextRequest(text=text,
use_vector_voice=use_vector_voice,
duration_scalar=duration_scalar)
return await self.conn.grpc_interface.SayText(say_text_request)


class AsyncRobot(Robot):
"""The AsyncRobot object is just like the Robot object, but allows multiple commands
Expand All @@ -868,7 +845,7 @@ class AsyncRobot(Robot):
# Create the robot connection
with anki_vector.AsyncRobot() as robot:
# Start saying text asynchronously
say_future = robot.say_text("Now is the time")
say_future = robot.behavior.say_text("Now is the time")
# Turn robot, wait for completion
turn_future = robot.behavior.turn_in_place(degrees(3*360))
turn_future.result()
Expand All @@ -890,7 +867,7 @@ class AsyncRobot(Robot):
# Connect to Vector
robot.connect()
# Start saying text asynchronously
say_future = robot.say_text("Now is the time")
say_future = robot.behavior.say_text("Now is the time")
# Turn robot, wait for completion
turn_future = robot.behavior.turn_in_place(degrees(3 * 360))
turn_future.result()
Expand Down
4 changes: 2 additions & 2 deletions examples/apps/remote_control/remote_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def handle_key(self, key_code, is_shift_down, is_alt_down, is_key_down):
anim_name = self.key_code_to_anim_name(key_code)
self.queue_action((self.vector.anim.play_animation, anim_name))
elif key_code == ord(' '):
self.queue_action((self.vector.say_text, self.text_to_say))
self.queue_action((self.vector.behavior.say_text, self.text_to_say))

def key_code_to_anim_name(self, key_code):
key_num = key_code - ord('0')
Expand All @@ -240,7 +240,7 @@ def key_code_to_anim_name(self, key_code):
return anim_name

def func_to_name(self, func):
if func == self.vector.say_text:
if func == self.vector.behavior.say_text:
return "say_text"
if func == self.vector.anim.play_animation:
return "play_anim"
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/01_hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main():
args = anki_vector.util.parse_command_args()
with anki_vector.Robot(args.serial) as robot:
print("Say 'Hello World'...")
robot.say_text("Hello World")
robot.behavior.say_text("Hello World")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/11_face_event_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def on_robot_observed_face(robot, event_type, event):
global said_text
if not said_text:
said_text = True
robot.say_text("I see a face!")
robot.behavior.say_text("I see a face!")
evt.set()

args = anki_vector.util.parse_command_args()
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/12_wake_word_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def on_wake_word(robot, event_type, event):
global wake_word_heard
if not wake_word_heard:
wake_word_heard = True
robot.say_text("Hello")
robot.behavior.say_text("Hello")
evt.set()

args = anki_vector.util.parse_command_args()
Expand Down

0 comments on commit 6001b30

Please sign in to comment.