3 from __future__
import division
6 from cv_bridge
import CvBridge
9 from distutils.version
import LooseVersion
12 from jsk_recognition_msgs.msg
import Spectrum
13 from sensor_msgs.msg
import Image
22 super(SpectrumToSpectrogram, self).
__init__()
27 spectrum_msg = rospy.wait_for_message(
'~spectrum', Spectrum)
28 spectrum_len = len(spectrum_msg.amplitude)
30 self.
spectrogram = np.zeros((0, spectrum_len), dtype=np.float32)
36 '~spectrum', Spectrum, self.
audio_cb)
38 '~spectrogram', Image, queue_size=1)
39 publish_rate = rospy.get_param(
43 period=rospy.Duration(1.0 / publish_rate),
47 if (LooseVersion(pkg_resources.get_distribution(
'rospy').version) >=
48 LooseVersion(
'1.12.0'))
and rospy.get_param(
'/use_sim_time',
None):
51 timer_kwargs[
'reset'] =
True
52 self.
timer = rospy.Timer(**timer_kwargs)
57 spectrum = np.array(msg.amplitude, dtype=np.float32)
62 time_now = rospy.Time.now()
73 spectrogram = self.
spectrogram.transpose(1, 0)[::-1, :]
74 spectrogram = cv2.resize(
77 spectrogram_msg = self.
bridge.cv2_to_imgmsg(spectrogram,
'32FC1')
82 if __name__ ==
'__main__':
83 rospy.init_node(
'audio_to_spectrogram')