Skip to content

Commit 11a2b1c

Browse files
708yamaguchiknorth55
authored andcommitted
Do not replace sound when other node is speaking
1 parent dcf3dc7 commit 11a2b1c

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

jsk_fetch_robot/jsk_fetch.rosinstall.melodic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
local-name: mikeferguson/robot_calibration
7272
uri: https://github.com/mikeferguson/robot_calibration.git
7373
version: 0.5.5
74+
# https://github.com/ros-drivers/audio_common/pull/173
7475
- git:
7576
local-name: ros-drivers/audio_common
7677
uri: https://github.com/ros-drivers/audio_common.git

jsk_fetch_robot/jsk_fetch_startup/scripts/battery_warning.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33

44
import actionlib
55
import rospy
6+
from sound_play.libsoundplay import SoundClient
67

78
from power_msgs.msg import BatteryState
8-
from sound_play.msg import SoundRequest
9-
from sound_play.msg import SoundRequestAction
10-
from sound_play.msg import SoundRequestGoal
119

1210

1311
class BatteryWarning(object):
1412
def __init__(self):
15-
self.client_en = actionlib.SimpleActionClient(
16-
'/sound_play', SoundRequestAction)
17-
self.client_jp = actionlib.SimpleActionClient(
18-
'/robotsound_jp', SoundRequestAction)
13+
self.client_en = SoundClient(sound_action='/sound_play', blocking=True)
14+
self.client_jp = SoundClient(sound_action='/robotsound_jp', blocking=True)
1915
self.duration = rospy.get_param('~duration', 180.0)
2016
self.threshold = rospy.get_param('~charge_level_threshold', 40.0)
2117
self.step = rospy.get_param('~charge_level_step', 10.0)
@@ -28,17 +24,13 @@ def __init__(self):
2824
self.is_charging = False
2925

3026
def _speak(self, client, speech_text, lang=None):
31-
client.wait_for_server(timeout=rospy.Duration(1.0))
32-
sound_goal = SoundRequestGoal()
33-
sound_goal.sound_request.sound = -3
34-
sound_goal.sound_request.command = 1
35-
sound_goal.sound_request.volume = self.volume
27+
client.actionclient.wait_for_server(timeout=rospy.Duration(1.0))
3628
if lang is not None:
37-
sound_goal.sound_request.arg2 = lang
38-
sound_goal.sound_request.arg = speech_text
39-
client.send_goal(sound_goal)
40-
client.wait_for_result()
41-
return client.get_result()
29+
client.say(speech_text, voice=lang, replace=False)
30+
else:
31+
client.say(speech_text, replace=False)
32+
client.actionclient.wait_for_result()
33+
return client.actionclient.get_result()
4234

4335
def _warn(self):
4436
if self.charge_level < self.threshold and not self.is_charging:

jsk_robot_common/jsk_robot_startup/scripts/boot_sound.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
# https://www.youtube.com/watch?v=HM-xG0qXaeA&&
44
# ffmpeg -i R2D2\ all\ Sounds\ -\ Star\ Wars\ free\ sounds.mp4 -ss 48 -t 10 R2D2.wav
55

6-
import rospy
7-
import time, socket, os
86
import netifaces as ni
9-
import rospkg
7+
import rospy
108

119
from sound_play.libsoundplay import SoundClient
12-
import actionlib
13-
from sound_play.msg import SoundRequestAction
1410

1511
if __name__ == "__main__":
1612
rospy.init_node("boot_sound")
@@ -19,32 +15,22 @@
1915
else:
2016
wav_file = "/usr/share/sounds/alsa/Front_Center.wav"
2117

22-
sound = SoundClient()
23-
time.sleep(1) # ???
24-
ac = actionlib.SimpleActionClient('sound_play', SoundRequestAction)
25-
ac.wait_for_server()
18+
sound = SoundClient(sound_action='sound_play', blocking=True)
19+
sound.actionclient.wait_for_server()
2620

27-
28-
interfaces = [x for x in ni.interfaces() if x[0:3] in ['eth', 'enp', 'wla', 'wlp'] and
29-
2 in ni.ifaddresses(x).keys()]
30-
if len(interfaces) > 0 :
31-
ip = ni.ifaddresses(interfaces[0])[2][0]['addr']
21+
if len(ni.ifaddresses('eth0')) > 2:
22+
ip = ni.ifaddresses('eth0')[2][0]['addr']
23+
elif len(ni.ifaddresses('wlan0')) > 2:
24+
ip = ni.ifaddresses('wlan0')[2][0]['addr']
3225
else:
3326
ip = None
3427

3528
# play sound
3629
rospy.loginfo("Playing {}".format(wav_file))
37-
sound.playWave(wav_file)
38-
time.sleep(10) # make sure to topic is going out
30+
sound.playWave(wav_file, replace=False)
3931

4032
# notify ip address
4133
ip_text = "My internet address is {}".format(ip)
4234
rospy.loginfo(ip_text)
4335
ip_text = ip_text.replace('.', ', ')
44-
sound.say(ip_text)
45-
time.sleep(1) # make sure to topic is going out
46-
47-
48-
49-
50-
36+
sound.say(ip_text, replace=False)

0 commit comments

Comments
 (0)