Skip to content
Snippets Groups Projects
Commit c5e57658 authored by Antonio Andriella's avatar Antonio Andriella
Browse files

Add methods for reproducing audio - hard coded

parent 94fbda0e
No related branches found
No related tags found
No related merge requests found
...@@ -163,39 +163,49 @@ class Robot: ...@@ -163,39 +163,49 @@ class Robot:
except IndexError: except IndexError:
print("The index is out of bound, we will set it to 0 for action index") print("The index is out of bound, we will set it to 0 for action index")
def provide_lev_1(self, speech, file): def provide_lev_1(self, speech, file, your_turn):
speech.play_file(file) #speech.play_file(file, 2)
#speech.play_file(your_turn, 1)
return file
def provide_lev_2_col(self, token, skt, speech, robot, file_Left, file_Center, file_Right): def provide_lev_2_col(self, token, skt, speech, robot, file_Left, file_Center, file_Right, your_turn):
board_cols = skt.get_board_size()[1] board_cols = skt.get_board_size()[1]
robot.look_at_user()
# we need to get the location of the current token # we need to get the location of the current token
# and get the two that are closer # and get the two that are closer
solution_location = skt.get_token_location(token) solution_location = skt.get_token_location(token)
sentence = ""
# if the right token is is the last column of the board # if the right token is is the last column of the board
if (solution_location == (board_cols) or solution_location == ((2 * board_cols)) or solution_location == ( if (solution_location == (board_cols) or solution_location == ((2 * board_cols)) or solution_location == (
3 * board_cols) or solution_location == (4 * board_cols)): 3 * board_cols) or solution_location == (4 * board_cols)):
speech.play_file(file_Right) sentence = file_Right
#speech.play_file(file_Right, 3)
#speech.play_file(your_turn, 1)
print("Solution is on the right") print("Solution is on the right")
elif (solution_location == 1 or solution_location == (board_cols + 1) or solution_location == ( elif (solution_location == 1 or solution_location == (board_cols + 1) or solution_location == (
board_cols * 2) + 1 or solution_location == (board_cols * 3) + 1): board_cols * 2) + 1 or solution_location == (board_cols * 3) + 1):
speech.play_file(file_Left) sentence = file_Left
#speech.play_file(file_Left, 3)
#speech.play_file(your_turn, 1)
print("Soluition in on the left") print("Soluition in on the left")
else: else:
speech.play_file(file_Center) sentence = file_Center
#speech.play_file(file_Center, 3)
#speech.play_file(your_turn, 1)
print("Solution is in the middle") print("Solution is in the middle")
return sentence
def provide_lev_2_row(self, token, skt, speech, file_1Row, file_2Row, file_3Row): def provide_lev_2_row(self, token, skt, speech, file_1Row, file_2Row, file_3Row):
# we need to get the location of the current token # we need to get the location of the current token
# and get the two that are closer # and get the two that are closer
solution_location = skt.get_token_location(token) solution_location = skt.get_token_location(token)
if solution_location>11 and solution_location<15: if solution_location>11 and solution_location<15:
print("second row") print("second row")
speech.play_file(file_2Row) speech.play_file(file_2Row, 3)
else: else:
print("first row") print("first row")
speech.play_file(file_1Row) speech.play_file(file_1Row, 3)
def move_token_back(self, token, skt): def move_token_back(self, token, skt):
...@@ -205,34 +215,37 @@ class Robot: ...@@ -205,34 +215,37 @@ class Robot:
return token_curr_loc, token_dest_loc return token_curr_loc, token_dest_loc
def provide_instructions(self, speech, file): def provide_instructions(self, speech, file1, file2):
speech.play_file(file) speech.play_file(file1, 10)
speech.play_file(file2, 10)
def provide_congratulation(self, speech, file): def provide_congratulation(self, speech, file):
speech.play_file(file) speech.play_file(file, 4)
def provide_pos_feedback(self, attempt, max_attempt, speech, robot, file): def provide_pos_feedback(self, attempt, max_attempt, speech, robot, file):
if attempt>max_attempt-1: attempt = np.random.randint(0, max_attempt)
attempt = np.random.randint(0, max_attempt)
#robot.head_noddling_yes() #robot.head_noddling_yes()
speech.play_file(file[attempt]) #speech.play_file(file[attempt],2)
return file[attempt]
def provide_neg_feedback(self, attempt, max_attempt, speech, robot, file): def provide_neg_feedback(self, attempt, max_attempt, speech, robot, file):
if attempt>max_attempt-1:
attempt = np.random.randint(0, max_attempt)
#robot.head_noddling_no()
speech.play_file(file[attempt])
attempt = np.random.randint(0, max_attempt)
#robot.head_noddling_no()
#speech.play_file(file[attempt], 2)
return file[attempt]
def provide_token_back(self, speech, file): def provide_token_back(self, speech, file):
speech.play_file(file) #speech.play_file(file, 2)
return file
def provide_game_completed(self, speech, file): def provide_game_completed(self, speech, file):
speech.play_file(file) #speech.play_file(file,4)
return file
def provide_illegal_move(self, speech, file): def provide_illegal_move(self, speech, file):
speech.play_file(file) #speech.play_file(file, 3)
return file
def provide_timeout(self, speech, file):
#speech.play_file(file, 3)
return file
# length=5 # length=5
# progress=1 # progress=1
# timeout=15 # timeout=15
......
...@@ -17,6 +17,10 @@ class SpeechUtterance(): ...@@ -17,6 +17,10 @@ class SpeechUtterance():
def reproduce_speech(self, sentence): def reproduce_speech(self, sentence):
rate = rospy.Rate(1) # 10hz rate = rospy.Rate(1) # 10hz
#check if the sentence is a string otherwise cast it
if not isinstance(sentence, str):
sentence = str(sentence)
while not rospy.is_shutdown(): while not rospy.is_shutdown():
connections = self.pub.get_num_connections() connections = self.pub.get_num_connections()
if connections>0: if connections>0:
...@@ -32,7 +36,7 @@ class SpeechUtterance(): ...@@ -32,7 +36,7 @@ class SpeechUtterance():
break break
#rospy.sleep(pause) #rospy.sleep(pause)
def play_file(self, file, volume=0.5): def play_file(self, file, timing, volume=0.5):
rospy.loginfo('Example: SoundClient play methods can take in an explicit' rospy.loginfo('Example: SoundClient play methods can take in an explicit'
' blocking parameter') ' blocking parameter')
soundhandle = SoundClient() # blocking = False by default soundhandle = SoundClient() # blocking = False by default
...@@ -41,7 +45,7 @@ class SpeechUtterance(): ...@@ -41,7 +45,7 @@ class SpeechUtterance():
sound_beep = soundhandle.waveSound(file, volume) sound_beep = soundhandle.waveSound(file, volume)
sound_beep.play() sound_beep.play()
rospy.sleep(0.5) # Let sound complete. rospy.sleep(timing) # Let sound complete.
# def main(): # def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment