Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
robot_behaviour
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antonio Andriella
robot_behaviour
Commits
f6759669
Commit
f6759669
authored
4 years ago
by
Antonio Andriella
Browse files
Options
Downloads
Patches
Plain Diff
Add callback to check if the reproduction has ended
parent
f8a78b61
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/robot_behaviour/speech_reproducer.py
+22
-46
22 additions, 46 deletions
src/robot_behaviour/speech_reproducer.py
with
22 additions
and
46 deletions
src/robot_behaviour/speech_reproducer.py
+
22
−
46
View file @
f6759669
...
@@ -16,10 +16,8 @@ class Speech():
...
@@ -16,10 +16,8 @@ class Speech():
self
.
client
=
actionlib
.
SimpleActionClient
(
'
/tts
'
,
TtsAction
)
self
.
client
=
actionlib
.
SimpleActionClient
(
'
/tts
'
,
TtsAction
)
self
.
sound_client
=
SoundClient
()
self
.
sound_client
=
SoundClient
()
self
.
language
=
language
self
.
language
=
language
self
.
feedback
=
0
self
.
reproduction_has_ended
=
False
self
.
text
=
""
def
event
(
self
,
event
):
def
event
(
self
,
event
):
#print("event {}".format(event))
return
{
return
{
1
:
'
TTS_EVENT_INITIALIZATION
'
,
1
:
'
TTS_EVENT_INITIALIZATION
'
,
2
:
'
TTS_EVENT_SHUTDOWN
'
,
2
:
'
TTS_EVENT_SHUTDOWN
'
,
...
@@ -33,64 +31,42 @@ class Speech():
...
@@ -33,64 +31,42 @@ class Speech():
}[
event
]
}[
event
]
def
feedbackCb
(
self
,
feedback
):
def
feedbackCb
(
self
,
feedback
):
print
(
"
event type:
"
+
self
.
event
(
feedback
.
event_type
))
r
=
rospy
.
Rate
(
20
)
print
(
"
timestamp:
"
+
str
(
feedback
.
timestamp
))
r
.
sleep
()
print
(
"
current word:
"
+
feedback
.
text_said
)
#rospy.loginfo("Feedback ")
print
(
"
next word:
"
+
feedback
.
next_word
)
print
(
"
-
"
)
def
text_to_speech
(
self
,
text
,
locked
=
False
,
threshold
=
10
):
def
activeCb
(
self
):
rospy
.
loginfo
(
"
Processing the goal
"
)
def
doneCb
(
self
,
state
,
result
):
rospy
.
loginfo
(
"
Action server is done.
"
)
self
.
reproduction_has_ended
=
True
def
text_to_speech
(
self
,
text
,
locked
=
False
):
#rospy.loginfo("Waiting for Server")
#rospy.loginfo("Waiting for Server")
self
.
client
.
wait_for_server
()
self
.
client
.
wait_for_server
()
#rospy.loginfo("Reached Server")
#rospy.loginfo("Reached Server")
goal
=
TtsGoal
()
goal
=
TtsGoal
()
goal
.
rawtext
.
text
=
text
goal
.
rawtext
.
text
=
text
length
=
len
(
text
)
goal
.
rawtext
.
lang_id
=
self
.
language
goal
.
rawtext
.
lang_id
=
self
.
language
t0
=
time
.
time
()
self
.
client
.
send_goal
(
goal
,
active_cb
=
self
.
activeCb
,
feedback_cb
=
self
.
feedbackCb
,
done_cb
=
self
.
doneCb
)
self
.
client
.
send_goal
(
goal
,
feedback_cb
=
self
.
feedbackCb
)
goal_state
=
self
.
client
.
get_state
()
if
locked
:
if
locked
:
self
.
client
.
wait_for_result
(
timeout
=
rospy
.
Duration
(
5
)
)
self
.
client
.
wait_for_result
()
response
=
self
.
client
.
get_result
()
if
goal_state
!=
GoalStatus
.
SUCCEEDED
:
self
.
client
.
stop_tracking_goal
()
return
def
cancel_reproduction
(
self
):
def
cancel_reproduction
(
self
):
rospy
.
loginfo
(
"
canceling...
"
)
rospy
.
loginfo
(
"
canceling...
"
)
self
.
text_to_speech
(
""
,
False
)
self
.
text_to_speech
(
""
,
False
)
rospy
.
loginfo
(
"
goal has been canceled
"
)
rospy
.
loginfo
(
"
goal has been canceled
"
)
def
get_status
(
self
):
if
self
.
feedback
==
"
TTS_EVENT_STARTED_PLAYING_WORD
"
:
return
True
#
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
speech
=
Speech
(
"
en_GB
"
)
speech
=
Speech
(
"
en_GB
"
)
text
=
"
This is the sentence you have to reproduce, for istance.
"
text
=
"
The solution is 112
"
start
=
time
.
time
()
speech
.
text_to_speech
(
text
,
False
,
0
)
t
=
speech
.
text_to_speech
(
text
,
False
,
1
)
t0
=
time
.
time
()
time_to_reproduce
=
5
print
(
time_to_reproduce
)
# rospy.sleep(time_to_reproduce)
elapsed_time
=
0
elapsed_time
=
0
# print("len:", time_to_reproduce)
while
(
elapsed_time
<
5
):
while
(
elapsed_time
<
time_to_reproduce
):
elapsed_time
=
time
.
time
()
-
t0
elapsed_time
=
time
.
time
()
-
start
print
(
"
Reproduction has ended?
"
,
speech
.
reproduction_has_ended
)
if
elapsed_time
>
2
:
speech
.
cancel_reproduction
()
print
(
"
speech
"
,
speech
.
client
.
get_state
())
break
#success_against = speech.text_to_speech("test again agaist you", True)
# while(elapsed_time<4):
# elapsed_time = time.time()-start
#speech.cancel_reproduction()
#while(speech.feedback!="TTS_EVENT_FINISHED_PLAYING_SENTENCE"):
# print("Do something else")
#print("We're out")
#while (speech.feedback)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment