はじめに
audio_commonパッケージは、音声の再生や録音など可能な音声関連のパッケージである。
ROS 1ではバイナリ提供されており、ROS 2 Foxyでは、audio_commonパッケージのros2ブランチをビルドすることで利用可能である。
しかし、ROS 2 Humbleでは、バイナリ提供はされていなく、また、audio_commonパッケージのros2ブランチをビルドするとエラーになってしまう。本記事では、ROS 2 Humbleでaudio_commonパッケージをビルドする方法を紹介する。
動作確認環境
- Ubuntu 22.04 x64
- ROS 2 Humble
エラー内容
audio_commonパッケージのros2ブランチの最新版をビルドすると以下のようになりエラーとなる。
cd ~/ros2_ws/src
git clone -b ros2 https://github.com/ros-drivers/audio_common
cd ~/ros2_ws
sudo apt update
rosdep install --from-paths src --ignore-src -r -y
colcon build --symlink-install --packages-up-to audio_common
Starting >>> audio_common_msgs
Finished <<< audio_common_msgs [7.42s]
Starting >>> audio_capture
Starting >>> audio_play
Starting >>> sound_play
--- stderr: sound_play
CMake Error at /opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:106 (add_custom_target):
add_custom_target cannot create target
"ament_cmake_python_symlink_sound_play" because another target with the
same name already exists. The existing target is a custom target created
in source directory "/root/ros2_ws/src/audio_common/sound_play". See
documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
/opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:39 (_ament_cmake_python_install_package)
CMakeLists.txt:36 (ament_python_install_package)
CMake Error at /opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:141 (add_custom_target):
add_custom_target cannot create target
"ament_cmake_python_build_sound_play_egg" because another target with the
same name already exists. The existing target is a custom target created
in source directory "/root/ros2_ws/src/audio_common/sound_play". See
documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
/opt/ros/humble/share/ament_cmake_python/cmake/ament_python_install_package.cmake:39 (_ament_cmake_python_install_package)
CMakeLists.txt:36 (ament_python_install_package)
---
Failed <<< sound_play [2.92s, exited with code 1]
Aborted <<< audio_capture [13.5s]
Aborted <<< audio_play [16.5s]
Summary: 1 package finished [24.7s]
1 package failed: sound_play
2 packages aborted: audio_capture audio_play
3 packages had stderr output: audio_capture audio_play sound_play
1 package not processed
エラーの詳細は、以下のissueで議論されている。
方法
issueにあるように、audio_commonのフォークブランチ「teapfw/audio_common humble_hotfixブランチ」を利用する。
このhumble_hotfixブランチは、2025年7月23日時点で本家audio_commonにはまだマージされていない。
cd ~/ros2_ws/src
git clone -b humble_hotfix https://github.com/teapfw/audio_common
cd ~/ros2_ws
sudo apt update
rosdep install --from-paths src --ignore-src -r -y
colcon build --symlink-install --packages-up-to audio_common
以下のようなメッセージが表示されれば成功。
Starting >>> audio_common_msgs
Finished <<< audio_common_msgs [7.50s]
Starting >>> audio_capture
Starting >>> audio_play
Starting >>> sound_play
Finished <<< sound_play [9.23s]
--- stderr: audio_capture
/root/ros2_ws/src/audio_common/audio_capture/src/audio_capture_node.cpp: In static member function ‘static gboolean audio_capture::AudioCaptureNode::onMessage(GstBus*, GstMessage*, gpointer)’:
/root/ros2_ws/src/audio_common/audio_capture/src/audio_capture_node.cpp:238:42: warning: unused parameter ‘bus’ [-Wunused-parameter]
238 | static gboolean onMessage (GstBus *bus, GstMessage *message, gpointer userData)
| ~~~~~~~~^~~
---
Finished <<< audio_capture [12.4s]
--- stderr: audio_play
/root/ros2_ws/src/audio_common/audio_play/src/audio_play_node.cpp: In static member function ‘static void audio_play::AudioPlayNode::cb_newpad(GstElement*, GstPad*, gpointer)’:
/root/ros2_ws/src/audio_common/audio_play/src/audio_play_node.cpp:158:41: warning: unused parameter ‘decodebin’ [-Wunused-parameter]
158 | static void cb_newpad (GstElement *decodebin, GstPad *pad,
| ~~~~~~~~~~~~^~~~~~~~~
---
Finished <<< audio_play [16.7s]
Starting >>> audio_common
Finished <<< audio_common [1.35s]
Summary: 5 packages finished [26.5s]
2 packages had stderr output: audio_capture audio_play
まとめ
ROS 2 Humbleでaudio_commonパッケージをビルドする手順を紹介した。ROS2 Humbleで音声関連のパッケージを利用したい場合は参考にしてほしい。音声再生の方法については、私の記事も参照してほしい。
参考