-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[audio_to_spectrogram] Add AudioAmplitudePlot node to visualize audio amplitude #2657
Conversation
7c7a460
to
945ab02
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the nice plotter and documentation!
This is because my code was ad-hoc, but can you make some of the code common?
# Audio topic config | ||
# The number of channels in audio data | ||
self.n_channel = rospy.get_param('~n_channel', 1) | ||
# Sampling rate of microphone (namely audio topic). | ||
self.mic_sampling_rate = rospy.get_param('~mic_sampling_rate', 16000) | ||
# Bits per one audio data | ||
bitdepth = rospy.get_param('~bitdepth', 16) | ||
if bitdepth == 16: | ||
self.dtype = 'int16' | ||
else: | ||
rospy.logerr("'~bitdepth' {} is unsupported.".format(bitdepth)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are the settings to convert audio stream and used in audio_to_spectrum.py
, too.
jsk_recognition/audio_to_spectrogram/scripts/audio_to_spectrum.py
Lines 18 to 30 in 6ff031d
# Audio topic config | |
# The number of channels in audio data | |
self.n_channel = rospy.get_param('~n_channel', 1) | |
# Sampling rate of microphone (namely audio topic). | |
mic_sampling_rate = rospy.get_param('~mic_sampling_rate', 16000) | |
# Period[s] to sample audio data for one fft | |
fft_sampling_period = rospy.get_param('~fft_sampling_period', 0.3) | |
# Bits per one audio data | |
bitdepth = rospy.get_param('~bitdepth', 16) | |
if bitdepth == 16: | |
self.dtype = 'int16' | |
else: | |
rospy.logerr("'~bitdepth' {} is unsupported.".format(bitdepth)) |
I think these codes should be shared.
Could you create python class like AudioBuffer
, which receives audio_common_msgs/AudioData
and create self.audio_buffer
buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Created AudioBuffer
class.
def audio_cb(self, msg): | ||
# Convert audio buffer to int array | ||
data = msg.data | ||
audio_buffer = np.frombuffer(data, dtype=self.dtype) | ||
# Retreive one channel data | ||
audio_buffer = audio_buffer[0::self.n_channel] | ||
# Save audio msg to audio_buffer | ||
with self.lock: | ||
self.audio_buffer = np.append( | ||
self.audio_buffer, audio_buffer) | ||
self.audio_buffer = self.audio_buffer[ | ||
-self.audio_buffer_len:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in another comment, could you create python class like AudioBuffer
?
jsk_recognition/audio_to_spectrogram/scripts/audio_to_spectrum.py
Lines 64 to 74 in 6ff031d
def audio_cb(self, msg): | |
# Convert audio buffer to int array | |
data = msg.data | |
audio_buffer = np.frombuffer(data, dtype=self.dtype) | |
# Retreive one channel data | |
audio_buffer = audio_buffer[0::self.n_channel] | |
# Save audio msg to audio_buffer | |
self.audio_buffer = np.append( | |
self.audio_buffer, audio_buffer) | |
self.audio_buffer = self.audio_buffer[ | |
-self.audio_buffer_len:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Created AudioBuffer
class.
self.ax.set_ylim((-self.maximum_amplitude, self.maximum_amplitude)) | ||
|
||
self.ax.legend(loc='upper right') | ||
if self.pub_img.get_num_connections() > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use ConnectionBasedTransport
?
In addition, if possible, could you create python class like AudioPlot
, which configures matplotlib
and can be used in both audio_amplitude_plot.py
and spectrum_plot.py
why did you create custom plot node instead of existing plotting tools (rqt / plotjuggler) |
I'm sorry I don't understand well. |
@iory I want to know the reason why you created the nose just to visualize audio amplitude |
Since sound is invisible, it is nice for the user to have it visualized. |
why you can not use rqt? or other plotting tools? |
FYI: |
OK. I'll take another way. |
I'm sorry, I'd like to ask you one point.
Also, when it comes out as image data, we are happy to be able to correspond with another image because it has a timestamp. |
@iory I see, LGTM |
8de398b
to
cf705fc
Compare
8f7f018
to
7e09365
Compare
[audio_to_spectrogram] Add AudioAmplitudePlot node to visualize audio amplitude #2657
What is this?
This PR adds a script to publish audio amplitude plot image.
The following video shows the audio amplitude visualized at this node while clapping.
This PR is based on #2654 .
audio_amplitude_plot--SLASH--output--SLASH--viz.mp4