本文整理汇总了Python中sound_play.libsoundplay.SoundClient.play方法的典型用法代码示例。如果您正苦于以下问题:Python SoundClient.play方法的具体用法?Python SoundClient.play怎么用?Python SoundClient.play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sound_play.libsoundplay.SoundClient
的用法示例。
在下文中一共展示了SoundClient.play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play_nonblocking
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
def play_nonblocking():
"""
Play the same sounds with manual pauses between them.
"""
rospy.loginfo('Example: Playing sounds in *non-blocking* mode.')
# NOTE: you must sleep at the beginning to let the SoundClient publisher
# establish a connection to the soundplay_node.
soundhandle = SoundClient(blocking=False)
rospy.sleep(1)
# In the non-blocking version you need to sleep between calls.
rospy.loginfo('Playing say-beep at full volume.')
soundhandle.playWave('say-beep.wav')
rospy.sleep(1)
rospy.loginfo('Playing say-beep at volume 0.3.')
soundhandle.playWave('say-beep.wav', volume=0.3)
rospy.sleep(1)
rospy.loginfo('Playing sound for NEEDS_PLUGGING.')
soundhandle.play(SoundRequest.NEEDS_PLUGGING)
rospy.sleep(1)
rospy.loginfo('Speaking some long string.')
soundhandle.say('It was the best of times, it was the worst of times.')
示例2: callback
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
def callback(data):
if str(data) == "data: Bark":
soundhandle = SoundClient()
rospy.sleep(1)
soundhandle.play(1)
pubshoot = rospy.Publisher('bark', String)
pubshoot.publish(String("Fire"))
示例3: __init__
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
class NavSpeak:
def __init__(self):
self.move_base_goal_sub = rospy.Subscriber("/move_base/goal", MoveBaseActionGoal, self.move_base_goal_callback, queue_size = 1)
self.move_base_result_sub = rospy.Subscriber("/move_base/result", MoveBaseActionResult, self.move_base_result_callback, queue_size = 1)
self.sound = SoundClient()
self.lang = "japanese" # speak japanese by default
if rospy.has_param("/nav_speak/lang"):
self.lang = rospy.get_param("/nav_speak/lang")
self.pub = rospy.Publisher('/robotsound_jp/goal', SoundRequestActionGoal, queue_size=1)
def move_base_goal_callback(self, msg):
self.sound.play(2)
def move_base_result_callback(self, msg):
text = "{}: {}".format(goal_status(msg.status.status), msg.status.text)
rospy.loginfo(text)
if self.lang == "japanese": # speak japanese
sound_goal = SoundRequestActionGoal()
sound_goal.goal_id.stamp = rospy.Time.now()
sound_goal.goal.sound_request.sound = -3
sound_goal.goal.sound_request.command = 1
sound_goal.goal.sound_request.volume = 1.0
sound_goal.goal.sound_request.arg2 = "jp"
if msg.status.status == GoalStatus.SUCCEEDED:
self.sound.play(1)
time.sleep(1)
if self.lang == "japanese":
sound_goal.goal.sound_request.arg = "到着しました"
self.pub.publish(sound_goal)
else:
self.sound.say(text)
elif msg.status.status == GoalStatus.PREEMPTED:
self.sound.play(2)
time.sleep(1)
if self.lang == "japanese":
sound_goal.goal.sound_request.arg = "別のゴールがセットされました"
self.pub.publish(sound_goal)
else:
self.sound.say(text)
elif msg.status.status == GoalStatus.ABORTED:
self.sound.play(3)
time.sleep(1)
if self.lang == "japanese":
sound_goal.goal.sound_request.arg = "中断しました"
self.pub.publish(sound_goal)
else:
self.sound.say(text)
else:
self.sound.play(4)
time.sleep(1)
self.sound.say(text)
示例4: play_blocking
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
def play_blocking():
"""
Play various sounds, blocking until each is completed before going to the
next.
"""
rospy.loginfo('Example: Playing sounds in *blocking* mode.')
soundhandle = SoundClient(blocking=True)
rospy.loginfo('Playing say-beep at full volume.')
soundhandle.playWave('say-beep.wav')
rospy.loginfo('Playing say-beep at volume 0.3.')
soundhandle.playWave('say-beep.wav', volume=0.3)
rospy.loginfo('Playing sound for NEEDS_PLUGGING.')
soundhandle.play(SoundRequest.NEEDS_PLUGGING)
rospy.loginfo('Speaking some long string.')
soundhandle.say('It was the best of times, it was the worst of times.')
示例5: __init__
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
class NavSpeak:
def __init__(self):
self.move_base_goal_sub = rospy.Subscriber("/move_base/goal", MoveBaseActionGoal, self.move_base_goal_callback, queue_size = 1)
self.move_base_result_sub = rospy.Subscriber("/move_base/result", MoveBaseActionResult, self.move_base_result_callback, queue_size = 1)
self.sound = SoundClient()
def move_base_goal_callback(self, msg):
self.sound.play(2)
def move_base_result_callback(self, msg):
text = "{}: {}".format(goal_status(msg.status.status), msg.status.text)
rospy.loginfo(text)
if msg.status.status == GoalStatus.SUCCEEDED:
self.sound.play(1)
elif msg.status.status == GoalStatus.PREEMPTED:
self.sound.play(2)
elif msg.status.status == GoalStatus.ABORTED:
self.sound.play(3)
else:
self.sound.play(4)
time.sleep(1)
self.sound.say(text)
示例6: play_explicit
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
def play_explicit():
rospy.loginfo('Example: SoundClient play methods can take in an explicit'
' blocking parameter')
soundhandle = SoundClient() # blocking = False by default
rospy.sleep(0.5) # Ensure publisher connection is successful.
sound_beep = soundhandle.waveSound("say-beep.wav", volume=0.5)
# Play the same sound twice, once blocking and once not. The first call is
# blocking (explicitly specified).
sound_beep.play(blocking=True)
# This call is not blocking (uses the SoundClient's setting).
sound_beep.play()
rospy.sleep(0.5) # Let sound complete.
# Play a blocking sound.
soundhandle.play(SoundRequest.NEEDS_UNPLUGGING, blocking=True)
# Create a new SoundClient where the default behavior *is* to block.
soundhandle = SoundClient(blocking=True)
soundhandle.say('Say-ing stuff while block-ing')
soundhandle.say('Say-ing stuff without block-ing', blocking=False)
rospy.sleep(1)
示例7: RunStopServer
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
class RunStopServer(object):
def __init__(self):
"""Provide dead-man-switch like server for handling wouse run-stops."""
rospy.Service("wouse_run_stop", WouseRunStop, self.service_cb)
self.run_stop = RunStop()
if DEAD_MAN_CONFIGURATION:
self.sound_client = SoundClient()
self.timeout = rospy.Duration(rospy.get_param('wouse_timeout', 1.5))
self.tone_period = rospy.Duration(10)
self.last_active_time = rospy.Time.now()
self.last_sound = rospy.Time.now()
rospy.Timer(self.timeout, self.check_receiving)
def check_receiving(self, event):
"""After timeout, check to ensure that activity is seen from wouse."""
silence = rospy.Time.now() - self.last_active_time
#print silence, " / ", self.timeout
if silence < self.timeout:
# print "Receiving"
return
#else:
# print "NOT receiving"
if (silence > self.timeout and (rospy.Time.now() - self.last_sound) > self.tone_period):
rospy.logwarn("RunStopServer has not heard from wouse recently.")
self.sound_client.play(3)#1
self.last_sound = rospy.Time.now()
def service_cb(self, req):
"""Handle service requests to start/stop run-stop. Used to reset."""
#print "Separation: ", req.time-self.last_active_time
self.last_active_time = req.time
#print "Delay: ", rospy.Time.now() - self.last_active_time
if req.stop:
return self.run_stop.stop()
elif req.start:
return self.run_stop.start()
else:
return True #only update timestamp
示例8: CarSound
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
class CarSound(object):
"""
car sound class
"""
def __init__(self):
self.entity = car_sound_pb2.SoundRequest()
self.soundhandle = SoundClient()
self.voice = 'voice_kal_diphone'
self.lasttime = rospy.get_time()
def callback_sound(self, data):
"""
new sound request
"""
print "New Sound Msg"
self.entity.ParseFromString(data.data)
print self.entity
if self.entity.mode == car_sound_pb2.SoundRequest.SAY:
self.soundhandle.say(self.entity.words, self.voice)
elif self.entity.mode == car_sound_pb2.SoundRequest.BEEP:
self.soundhandle.play(SoundRequest.NEEDS_PLUGGING)
self.lasttime = rospy.get_time()
示例9: sleep
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
print
#print 'Try to play wave files that do not exist.'
#soundhandle.playWave('17')
#soundhandle.playWave('dummy')
#print 'say'
#soundhandle.say('Hello world!')
#sleep(3)
#
print 'wave'
soundhandle.playWave('say-beep.wav')
sleep(2)
print 'plugging'
soundhandle.play(SoundRequest.NEEDS_PLUGGING)
sleep(2)
print 'unplugging'
soundhandle.play(SoundRequest.NEEDS_UNPLUGGING)
sleep(2)
print 'plugging badly'
soundhandle.play(SoundRequest.NEEDS_PLUGGING_BADLY)
sleep(2)
print 'unplugging badly'
soundhandle.play(SoundRequest.NEEDS_UNPLUGGING_BADLY)
sleep(2)
s1 = soundhandle.builtinSound(SoundRequest.NEEDS_UNPLUGGING_BADLY)
示例10: __init__
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
class voice_cmd_vel:
def __init__(self):
rospy.on_shutdown(self.cleanup)
self.speed = 0.1
self.buildmap = False
self.follower = False
self.navigation = False
self.msg = Twist()
# Create the sound client object
self.soundhandle = SoundClient()
rospy.sleep(1)
self.soundhandle.stopAll()
# Announce that we are ready for input
rospy.sleep(1)
self.soundhandle.say('Hi, my name is Petrois')
rospy.sleep(3)
self.soundhandle.say("Say one of the navigation commands")
# publish to cmd_vel, subscribe to speech output
self.pub_ = rospy.Publisher("cmd_vel", Twist, queue_size=2)
rospy.Subscriber('recognizer/output', String, self.speechCb)
r = rospy.Rate(10.0)
while not rospy.is_shutdown():
self.pub_.publish(self.msg)
r.sleep()
def speechCb(self, msg):
rospy.loginfo(msg.data)
if msg.data.find("fast") > -1:
if self.speed != 0.3:
self.soundhandle.say('Speeding up')
if self.msg.linear.x > 0:
self.msg.linear.x = 0.3
elif self.msg.linear.x < 0:
self.msg.linear.x = -0.3
if self.msg.angular.z >0:
self.msg.angular.z = 0.3
elif self.msg.angular.z < 0:
self.msg.angular.z = -0.3
self.speed = 0.3
else:
self.soundhandle.say('Already at full speed')
if msg.data.find("half") > -1:
if self.speed != 0.2:
self.soundhandle.say('Going at half speed')
if self.msg.linear.x > 0:
self.msg.linear.x = 0.2
elif self.msg.linear.x < 0:
self.msg.linear.x = -0.2
if self.msg.angular.z >0:
self.msg.angular.z = 0.2
elif self.msg.angular.z < 0:
self.msg.angular.z = -0.2
self.speed = 0.2
else:
self.soundhandle.say('Already at half speed')
if msg.data.find("slow") > -1:
if self.speed != 0.1:
self.soundhandle.say('Slowing down')
if self.msg.linear.x > 0:
self.msg.linear.x = 0.1
elif self.msg.linear.x < 0:
self.msg.linear.x = -0.1
if self.msg.angular.z >0:
self.msg.angular.z = 0.1
elif self.msg.angular.z < 0:
self.msg.angular.z = -0.1
self.speed = 0.1
else:
self.soundhandle.say('Already at slow speed')
if msg.data.find("forward") > -1:
self.soundhandle.play(1)
self.msg.linear.x = self.speed
self.msg.angular.z = 0
elif msg.data.find("left") > -1:
self.soundhandle.play(1)
if self.msg.linear.x != 0:
if self.msg.angular.z < self.speed:
self.msg.angular.z += 0.05
else:
self.msg.angular.z = self.speed*2
elif msg.data.find("right") > -1:
self.soundhandle.play(1)
if self.msg.linear.x != 0:
if self.msg.angular.z > -self.speed:
self.msg.angular.z -= 0.05
else:
self.msg.angular.z = -self.speed*2
elif msg.data.find("back") > -1:
self.soundhandle.play(1)
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
#.........这里部分代码省略.........
self.pub.publish(self.msg)
def send_goal(self, location_name):
location = self.locations.get(location_name)
# Set up goal location
self.goal = MoveBaseGoal()
self.goal.target_pose.pose = location
self.goal.target_pose.header.frame_id = 'map'
self.goal.target_pose.header.stamp = rospy.Time.now()
rospy.loginfo(self.goal)
# Let the user know where the robot is going next
rospy.loginfo("Going to: " + str(location_name))
self.soundhandle.say("Going to " + str(location_name))
# Start the robot toward the next location
self.move_base.send_goal(self.goal)
def run_follower(self, on):
if on and self.follower == False:
self.msg = Twist()
subprocess.Popen(['roslaunch', 'pioneer_utils', 'simple-follower.launch'])
self.soundhandle.say('Okay. Show me the way')
self.follower = True
elif on and self.follower:
self.soundhandle.say('Already in follower mode')
elif on == False and self.follower:
self.msg = Twist()
subprocess.Popen(['rosnode', 'kill', 'turtlebot_follower'])
self.follower = False
self.soundhandle.say('Follower mode disabled')
def forward(self):
self.soundhandle.play(1)
self.msg.linear.x = self.speed
self.msg.angular.z = 0
def backward(self):
self.soundhandle.play(1)
self.msg.linear.x = -self.speed
self.msg.angular.z = 0
def left(self):
self.soundhandle.play(1)
self.msg.linear.x = 0
self.msg.angular.z = self.speed*2
def right(self):
self.soundhandle.play(1)
self.msg.linear.x = 0
self.msg.angular.z = -self.speed*2
def stop(self):
self.move_base.cancel_goal()
self.run_follower(False)
self.msg = Twist()
self.soundhandle.play(1)
def set_speed(self, vel):
if self.msg.linear.x > 0:
self.msg.linear.x = vel
elif self.msg.linear.x < 0:
self.msg.linear.x = -vel
if self.msg.angular.z >0:
self.msg.angular.z = vel
elif self.msg.angular.z < 0:
示例12: len
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
# Author: Blaise Gassend
import sys
if __name__ == '__main__':
if len(sys.argv) != 2 or sys.argv[1] == '--help':
print 'Usage: %s <sound_id>'%sys.argv[0]
print
print 'Plays one of the built-in sounds based on its integer ID. Look at the sound_play/SoundRequest message definition for IDs.'
exit(1)
# Import here so that usage is fast.
import rospy
from sound_play.msg import SoundRequest
from sound_play.libsoundplay import SoundClient
rospy.init_node('play', anonymous = True)
soundhandle = SoundClient()
rospy.sleep(1)
num = int(sys.argv[1])
print 'Playing sound %i.'%num
soundhandle.play(num)
rospy.sleep(1)
示例13: sleep
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
soundhandle = 0
def sleep(t):
try:
rospy.sleep(t)
except:
pass
def voice_play_callback(data):
global soundhandle
s = soundhandle.voiceSound(data.data)
s.play()
sleep(2)
if __name__ == '__main__':
rospy.init_node('robot_voice_node', anonymous=True)
rospy.Subscriber("robot_voice", String, voice_play_callback)
global soundhandle
soundhandle = SoundClient()
rospy.sleep(1)
soundhandle.stopAll()
soundhandle.play(SoundRequest.NEEDS_PLUGGING)
sleep(1)
global soundhandle
s = soundhandle.voiceSound('Ass slam aly kum sir. How can I be of assistance')
s.play()
sleep(3)
rospy.spin()
示例14: onlineAnomalyDetection
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
#.........这里部分代码省略.........
self.init_time = rospy.get_time()
self.lGripperPosition = None
self.lGripperRotation = None
self.mic = None
self.grips = []
self.spoon = None
self.force = None
self.torque = None
self.jointAngles = None
self.jointVelocities = None
self.objectCenter = None
self.likelihoods = []
self.audioTool.reset(self.init_time)
def run(self):
"""Overloaded Thread.run, runs the update
method once per every xx milliseconds."""
# rate = rospy.Rate(1000) # 25Hz, nominally.
while not self.cancelled:
if self.isRunning and self.updateNumber > self.lastUpdateNumber and self.objectCenter is not None:
self.lastUpdateNumber = self.updateNumber
if not self.processData(): continue
if not self.anomalyOccured and len(self.forces) > 15:
# Perform anomaly detection
(anomaly, error) = self.hmm.anomaly_check(self.forces, self.distances, self.angles, self.audios, self.minThresholds*1.5) #temp
print 'Anomaly error:', error
if anomaly:
if self.isScooping:
self.interruptPublisher.publish('Interrupt')
else:
self.interruptPublisher.publish('InterruptHead')
self.anomalyOccured = True
self.soundHandle.play(2)
print 'AHH!! There is an anomaly at time stamp', rospy.get_time() - self.init_time, (anomaly, error)
fig = plt.figure()
for i, modality in enumerate([[self.forces] + onlineHMM.trainData[0][:13], [self.distances] + onlineHMM.trainData[1][:13], [self.angles] + onlineHMM.trainData[2][:13], [self.audios] + onlineHMM.trainData[3][:13]]):
ax = plt.subplot(int('41' + str(i+1)))
for index, (modal, times) in enumerate(zip(modality, [self.times] + onlineHMM.trainTimeList[:3])):
ax.plot(times, modal, label='%d' % index)
ax.legend()
fig.savefig('/home/dpark/git/hrl-assistive/hrl_multimodal_anomaly_detection/src/hrl_multimodal_anomaly_detection/fooboohooyou.pdf')
print "saved pdf file"
rospy.sleep(2.0)
# plt.show()
# rate.sleep()
print 'Online anomaly thread cancelled'
def cancel(self, cancelAudio=True):
self.isRunning = False
if cancelAudio:
self.audioTool.cancel()
self.saveData()
rospy.sleep(1.0)
def saveData(self):
# TODO Save data (Check with daehyung if any more data should be added)
data = dict()
data['forces'] = self.forces
data['distances'] = self.distances
data['angles'] = self.angles
data['audios'] = self.audios
data['forcesRaw'] = self.forcesRaw
data['distancesRaw'] = self.distancesRaw
data['anglesRaw'] = self.anglesRaw
示例15: len
# 需要导入模块: from sound_play.libsoundplay import SoundClient [as 别名]
# 或者: from sound_play.libsoundplay.SoundClient import play [as 别名]
# Author: Blaise Gassend
import sys
if __name__ == '__main__':
if len(sys.argv) < 2 or len(sys.argv) > 3 or sys.argv[1] == '--help':
print 'Usage: %s <sound_id> [volume]'%sys.argv[0]
print
print 'Plays one of the built-in sounds based on its integer ID. Look at the sound_play/SoundRequest message definition for IDs.\n The (optional) volume parameter sets the volume for the sound as a value between 0 and 1.0, where 0 is mute.'
exit(1)
# Import here so that usage is fast.
import rospy
from sound_play.msg import SoundRequest
from sound_play.libsoundplay import SoundClient
rospy.init_node('play', anonymous = True)
soundhandle = SoundClient()
rospy.sleep(1)
num = int(sys.argv[1])
volume = float(sys.argv[2]) if len(sys.argv) == 3 else 1.0
print 'Playing sound %i.'%num
soundhandle.play(num, volume)
rospy.sleep(1)