18 from collections
import defaultdict
23 from dynamic_reconfigure.server
import Server
24 from naoqi_sensors_py.cfg
import NaoqiMicrophoneConfig
25 from naoqi_bridge_msgs.msg
import AudioBuffer
27 from naoqi
import ALModule, ALBroker, ALProxy
31 NaoqiNode.__init__(self, name)
33 ALModule.__init__(self, name)
42 rospy.logerr(
"Error when creating proxy on ALAudioDevice:")
48 self.
microVersion = self.robotProxy._getMicrophoneConfig()
50 rospy.logwarn(
"Could not retrieve microphone version:")
52 rospy.logwarn(
"Microphone channel map might not be accurate.")
56 self.
config = defaultdict(returnNone)
59 self.
pub_audio_ = rospy.Publisher(
'~audio_raw', AudioBuffer)
66 Reconfigure the microphones 68 rospy.loginfo(
'reconfigure changed')
69 if self.pub_audio_.get_num_connections() == 0:
70 rospy.loginfo(
'Changes recorded but not applied as nobody is subscribed to the ROS topics.')
71 self.config.update(new_config)
76 rospy.loginfo(
'subscribed to audio proxy, since this is the first listener')
77 self.audioProxy.setClientPreferences(self.getName(), new_config[
'frequency'], 0, 0)
78 self.audioProxy.subscribe(self.getName())
81 self.config.update(new_config)
88 if self.pub_audio_.get_num_connections() == 0
and self.
isSubscribed:
89 rospy.loginfo(
'Unsubscribing from audio bridge as nobody listens to the topics.')
92 elif self.pub_audio_.get_num_connections() > 0
and not self.
isSubscribed:
99 self.myBroker.shutdown()
102 self.audioProxy.unsubscribe(self.name)
105 def processRemote(self, nbOfInputChannels, fNbOfInputSamples, timeStamp, inputBuff):
106 audio_msg = AudioBuffer()
111 for i
in range (0,len(inputBuff)/2) :
112 mictmp.append(ord(inputBuff[2*i])+ord(inputBuff[2*i+1])*256)
115 for i
in range (0,len(mictmp)) :
116 if mictmp[i]>=32768 :
117 mictmp[i]=mictmp[i]-65536
119 if self.
config[
'use_ros_time']:
120 audio_msg.header.stamp = rospy.Time.now()
122 audio_msg.header.stamp = rospy.Time(timeStamp)
124 audio_msg.frequency = self.
config[
'frequency']
130 audio_msg.channelMap = channels
132 audio_msg.data = mictmp
133 self.pub_audio_.publish(audio_msg)
def reconfigure(self, new_config, level)
def processRemote(self, nbOfInputChannels, fNbOfInputSamples, timeStamp, inputBuff)
def get_proxy(self, name, warn=True)