Skip to content

Commit 6001b30

Browse files
author
Michelle Sintov
committed
VIC-5166 Move say_text from robot to behavior (#82)
1 parent ee0b6cc commit 6001b30

7 files changed

Lines changed: 32 additions & 32 deletions

File tree

anki_vector/behavior.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,29 @@ async def drive_on_charger(self):
175175
drive_on_charger_request = protocol.DriveOnChargerRequest()
176176
return await self.grpc_interface.DriveOnCharger(drive_on_charger_request)
177177

178+
@connection.on_connection_thread()
179+
async def say_text(self, text: str, use_vector_voice: bool = True, duration_scalar: float = 1.0) -> protocol.SayTextResponse:
180+
"""Make Vector speak text.
181+
182+
.. testcode::
183+
184+
import anki_vector
185+
with anki_vector.Robot() as robot:
186+
robot.behavior.say_text("Hello World")
187+
188+
:param text: The words for Vector to say.
189+
:param use_vector_voice: Whether to use Vector's robot voice
190+
(otherwise, he uses a generic human male voice).
191+
:param duration_scalar: Adjust the relative duration of the
192+
generated text to speech audio.
193+
194+
:return: object that provides the status and utterance state
195+
"""
196+
say_text_request = protocol.SayTextRequest(text=text,
197+
use_vector_voice=use_vector_voice,
198+
duration_scalar=duration_scalar)
199+
return await self.conn.grpc_interface.SayText(say_text_request)
200+
178201
@connection.on_connection_thread()
179202
async def set_eye_color(self, hue: float, saturation: float) -> protocol.SetEyeColorResponse:
180203
"""Set Vector's eye color.

anki_vector/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def on_robot_observed_face(robot, event_type, event):
273273
global said_text
274274
if not said_text:
275275
said_text = True
276-
robot.say_text("I see a face!")
276+
robot.behavior.say_text("I see a face!")
277277
evt.set()
278278
279279
args = anki_vector.util.parse_command_args()
@@ -358,7 +358,7 @@ def on_robot_observed_face(robot, event_type, event):
358358
global said_text
359359
if not said_text:
360360
said_text = True
361-
robot.say_text("I see a face!")
361+
robot.behavior.say_text("I see a face!")
362362
evt.set()
363363
364364
args = anki_vector.util.parse_command_args()

anki_vector/robot.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -829,29 +829,6 @@ async def get_network_state(self) -> protocol.NetworkStateResponse:
829829
get_network_state_request = protocol.NetworkStateRequest()
830830
return await self.conn.grpc_interface.NetworkState(get_network_state_request)
831831

832-
@connection.on_connection_thread()
833-
async def say_text(self, text: str, use_vector_voice: bool = True, duration_scalar: float = 1.0) -> protocol.SayTextResponse:
834-
"""Make Vector speak text.
835-
836-
.. testcode::
837-
838-
import anki_vector
839-
with anki_vector.Robot() as robot:
840-
robot.say_text("Hello World")
841-
842-
:param text: The words for Vector to say.
843-
:param use_vector_voice: Whether to use Vector's robot voice
844-
(otherwise, he uses a generic human male voice).
845-
:param duration_scalar: Adjust the relative duration of the
846-
generated text to speech audio.
847-
848-
:return: object that provides the status and utterance state
849-
"""
850-
say_text_request = protocol.SayTextRequest(text=text,
851-
use_vector_voice=use_vector_voice,
852-
duration_scalar=duration_scalar)
853-
return await self.conn.grpc_interface.SayText(say_text_request)
854-
855832

856833
class AsyncRobot(Robot):
857834
"""The AsyncRobot object is just like the Robot object, but allows multiple commands
@@ -868,7 +845,7 @@ class AsyncRobot(Robot):
868845
# Create the robot connection
869846
with anki_vector.AsyncRobot() as robot:
870847
# Start saying text asynchronously
871-
say_future = robot.say_text("Now is the time")
848+
say_future = robot.behavior.say_text("Now is the time")
872849
# Turn robot, wait for completion
873850
turn_future = robot.behavior.turn_in_place(degrees(3*360))
874851
turn_future.result()
@@ -890,7 +867,7 @@ class AsyncRobot(Robot):
890867
# Connect to Vector
891868
robot.connect()
892869
# Start saying text asynchronously
893-
say_future = robot.say_text("Now is the time")
870+
say_future = robot.behavior.say_text("Now is the time")
894871
# Turn robot, wait for completion
895872
turn_future = robot.behavior.turn_in_place(degrees(3 * 360))
896873
turn_future.result()

examples/apps/remote_control/remote_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def handle_key(self, key_code, is_shift_down, is_alt_down, is_key_down):
231231
anim_name = self.key_code_to_anim_name(key_code)
232232
self.queue_action((self.vector.anim.play_animation, anim_name))
233233
elif key_code == ord(' '):
234-
self.queue_action((self.vector.say_text, self.text_to_say))
234+
self.queue_action((self.vector.behavior.say_text, self.text_to_say))
235235

236236
def key_code_to_anim_name(self, key_code):
237237
key_num = key_code - ord('0')
@@ -240,7 +240,7 @@ def key_code_to_anim_name(self, key_code):
240240
return anim_name
241241

242242
def func_to_name(self, func):
243-
if func == self.vector.say_text:
243+
if func == self.vector.behavior.say_text:
244244
return "say_text"
245245
if func == self.vector.anim.play_animation:
246246
return "play_anim"

examples/tutorials/01_hello_world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
args = anki_vector.util.parse_command_args()
2727
with anki_vector.Robot(args.serial) as robot:
2828
print("Say 'Hello World'...")
29-
robot.say_text("Hello World")
29+
robot.behavior.say_text("Hello World")
3030

3131

3232
if __name__ == "__main__":

examples/tutorials/11_face_event_subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def on_robot_observed_face(robot, event_type, event):
4141
global said_text
4242
if not said_text:
4343
said_text = True
44-
robot.say_text("I see a face!")
44+
robot.behavior.say_text("I see a face!")
4545
evt.set()
4646

4747
args = anki_vector.util.parse_command_args()

examples/tutorials/12_wake_word_subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def on_wake_word(robot, event_type, event):
4141
global wake_word_heard
4242
if not wake_word_heard:
4343
wake_word_heard = True
44-
robot.say_text("Hello")
44+
robot.behavior.say_text("Hello")
4545
evt.set()
4646

4747
args = anki_vector.util.parse_command_args()

0 commit comments

Comments
 (0)