mgonzs13/audio_common
mgonzs13/audio_common has 37 GitHub stars and 22 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-14 18:27 UTC. Last push 2026-10-29.
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
About
A PortAudio based audio_common with text to speech for ROS 2
Creative & MediaREADME.md
Originalaudio_capture
This repositiory provides a set of ROS 2 packages for audio. It provides a C++ version to capture and play audio data using PortAudio.
| ROS 2 Distro | Branch | Build status | Docker Image |
|---|---|---|---|
| Foxy | main |
||
| Galactic | main |
||
| Humble | main |
||
| Iron | main |
||
| Jazzy | main |
||
| Kilted | main |
||
| Lyrical | main |
||
| Rolling | main |
- |
Table of Contents
Installation
cd ~/ros2_ws/src
git clone https://github.com/mgonzs13/audio_common.git
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -r -y
colcon build
Docker
You can create a docker image to test audio_common. Use the following command inside the directory of audio_common.
docker build -t audio_common .
After the image is created, run a docker container with the following command.
docker run -it --rm --device /dev/snd audio_common
Nodes
audio_capturer_node
Node to obtain audio data from a microphone and publish it into the audio topic.
Click to expand
Parameters
format: Specifies the audio format to be used for capturing. Possible values are:
1(paFloat32 - 32-bit floating point)2(paInt32 - 32-bit integer)8(paInt16 - 16-bit integer)16(paInt8 - 8-bit integer)32(paUInt8 - 8-bit unsigned integer)
Default:
8(paInt16)The integer values correspond to PortAudio sample format flags.
channels: The number of audio channels to capture. Typically,
1for mono and2for stereo. Default:1rate: The sample rate that is how many samples per second should be captured. Default:
16000chunk: The size of each audio frame. Default:
512device: The ID of the audio input device. A value of
-1indicates that the default audio input device should be used. Default:-1frame_id: An identifier for the audio frame. This can be useful for synchronizing audio data with other data streams. Default:
""
ROS 2 Interfaces
- audio: Topic to publish the audio data captured from the microphone. Type:
audio_common_msgs/msg/AudioStamped
audio_player_node
Node to play the audio data obtained from the audio topic.
Click to expand
Parameters
channels: The number of audio channels to play. Typically,
1for mono and2for stereo. Default:2- The node automatically handles conversion between mono and stereo formats if needed.
rate: The output sample rate used to open the selected PortAudio output device. If set to
0, the node uses the device default output sample rate. Incoming audio is resampled internally when its sample rate differs from this value. Default:0device: The ID of the audio output device. A value of
-1indicates that the default audio output device should be used. Default:-1publish_reference: Publish the played frames on the
playedtopic. Default:true
The player uses a continuous PortAudio callback and a playback queue, so the device is kept fed with silence when no audio is queued. The reference topic therefore carries the actual device output, including silence, which is what an AEC needs for the far-end signal.
ROS 2 Interfaces
audio: Topic subscriber to get the audio data to be played. Type:
audio_common_msgs/msg/AudioStampedplayed: Topic publisher for the exact frames written to the output device. Type:
audio_common_msgs/msg/AudioStamped(whenpublish_referenceis true)
Topic names are fixed defaults; use standard ROS 2 remappings (for example, -r played:=/audio/played) to change them.
music_node
Node to play music from audio files in wav format.
Click to expand
Parameters
chunk: The size of each audio frame. Default:
2048frame_id: An identifier for the audio frame. This can be useful for synchronizing audio data with other data streams. Default:
""
ROS 2 Interfaces
audio: Topic to publish the audio data from the files. Type:
audio_common_msgs/msg/AudioStampedmusic_play: Service to play audio files. Type:
audio_common_msgs/srv/MusicPlay- Parameters:
audio: Name of a built-in audio sample (e.g., "elevator")file_path: Path to a custom WAV file (ignored if audio is specified)loop: Boolean to indicate if the audio should loop. Default:false
- Parameters:
music_stop: Service to stop the currently playing music. Type:
std_srvs/srv/Triggermusic_pause: Service to pause the currently playing music. Type:
std_srvs/srv/Triggermusic_resume: Service to resume paused music. Type:
std_srvs/srv/Trigger
tts_node
Node to generate audio from text (TTS) using espeak.
Click to expand
Parameters
chunk: The size of each audio frame. Default:
4096frame_id: An identifier for the audio frame. This can be useful for synchronizing audio data with other data streams. Default:
""
ROS 2 Interfaces
audio: Topic publisher to send the audio data generated by the TTS. Type:
audio_common_msgs/msg/AudioStampedsay: Action to generate audio data from a text. Type:
audio_common_msgs/action/TTS- Goal:
text: The text to convert to speechlanguage: The language to use for speech synthesis. Default:"en"volume: The volume of the generated speech (0.0-1.0). Default:1.0rate: The speech rate (1.0 is normal speed). Default:1.0
- Feedback:
audio: The audio being currently played
- Result:
text: The text that was converted to speech
- Goal:
aec_node
Node to remove the speaker's audio from the microphone signal (acoustic echo cancellation), so a robot can keep listening while tts_node or music_node is playing. It subscribes to a microphone topic (audio) and a playback reference topic (audio_reference), and publishes cleaned mono audio on audio_clean. Echo cancellation is provided by WebRTC AudioProcessing.
Click to expand
ROS 2 Interfaces
audio: Microphone input topic. Type:
audio_common_msgs/msg/AudioStampedaudio_reference: Playback reference topic. Point it at the player's
playedtopic so the AEC receives the exact frames written to the device; the older wiring remaps both the playback source andaudio_player_nodeto this topic. Type:audio_common_msgs/msg/AudioStampedaudio_clean: Cleaned mono output. Type:
audio_common_msgs/msg/AudioStamped
See audio_aec/README.md for the parameters, the TTS echo example, and tuning.
Demos
Audio Capturer/Player
ros2 run audio_common audio_capturer_node
ros2 run audio_common audio_player_node
TTS
ros2 run audio_common tts_node
ros2 run audio_common audio_player_node
ros2 action send_goal /say audio_common_msgs/action/TTS "{'text': 'Hello World'}"
Advanced TTS example with additional parameters:
ros2 action send_goal /say audio_common_msgs/action/TTS "{'text': 'Hello World', 'language': 'en-us', 'volume': 0.8, 'rate': 1.2}"
Music Player
ros2 run audio_common music_node
ros2 run audio_common audio_player_node
Play a built-in sample:
ros2 service call /music_play audio_common_msgs/srv/MusicPlay "{audio: 'elevator'}"
Play a custom WAV file:
ros2 service call /music_play audio_common_msgs/srv/MusicPlay "{file_path: '/path/to/your/file.wav'}"
Play with looping enabled:
ros2 service call /music_play audio_common_msgs/srv/MusicPlay "{audio: 'elevator', loop: true}"
Control playback:
ros2 service call /music_pause std_srvs/srv/Trigger "{}"
ros2 service call /music_resume std_srvs/srv/Trigger "{}"
ros2 service call /music_stop std_srvs/srv/Trigger "{}"