4 from cv_bridge
import CvBridge
8 from jsk_recognition_msgs.msg
import Spectrum
9 from sensor_msgs.msg
import Image
18 super(SpectrumToSpectrogram, self).
__init__()
23 spectrum_msg = rospy.wait_for_message(
'~spectrum', Spectrum)
24 spectrum_len = len(spectrum_msg.amplitude)
26 self.
spectrogram = np.zeros((0, spectrum_len), dtype=np.float32)
32 '~spectrum', Spectrum, self.
audio_cb)
34 '~spectrogram', Image, queue_size=1)
35 publish_rate = rospy.get_param(
45 spectrum = np.array(msg.amplitude, dtype=np.float32)
48 self.spectrum_stamp.append(msg.header.stamp)
50 time_now = rospy.Time.now()
58 if self.spectrogram.shape[0] == 0:
61 spectrogram = self.spectrogram.transpose(1, 0)[::-1, :]
62 spectrogram = cv2.resize(
65 spectrogram_msg = self.bridge.cv2_to_imgmsg(spectrogram,
'32FC1')
67 self.pub_spectrogram.publish(spectrogram_msg)
70 if __name__ ==
'__main__':
71 rospy.init_node(
'audio_to_spectrogram')
def timer_cb(self, timer)