diff --git a/mini_pupper_music/launch/music.launch.py b/mini_pupper_music/launch/music.launch.py index c04b169..3c85a0f 100644 --- a/mini_pupper_music/launch/music.launch.py +++ b/mini_pupper_music/launch/music.launch.py @@ -1,7 +1,6 @@ from launch import LaunchDescription from launch_ros.actions import Node -from launch.substitutions import LaunchConfiguration -from launch.actions import DeclareLaunchArgument, LogInfo + def generate_launch_description(): music_server_node = Node( @@ -12,4 +11,4 @@ def generate_launch_description(): ) return LaunchDescription([ music_server_node - ]) \ No newline at end of file + ]) diff --git a/mini_pupper_music/mini_pupper_music/music_server.py b/mini_pupper_music/mini_pupper_music/music_server.py index f1a1206..cd2da76 100644 --- a/mini_pupper_music/mini_pupper_music/music_server.py +++ b/mini_pupper_music/mini_pupper_music/music_server.py @@ -9,6 +9,7 @@ import os from ament_index_python.packages import get_package_share_directory + class SoundPlayerNode(Node): def __init__(self): super().__init__('mini_pupper_music_service') @@ -53,7 +54,7 @@ def play_sound_thread(self): file_name = 'resource/robot1.wav' package_path = get_package_share_directory(package_name) sound_file = os.path.join(package_path, file_name) - + data, fs = sf.read(sound_file, dtype='float32') while self.is_playing: sd.play(data, fs) @@ -67,6 +68,7 @@ def stop_sound(self): # If the thread is still running, stop the sound playback sd.stop() + def main(args=None): rclpy.init(args=args) sound_player_node = SoundPlayerNode() @@ -74,5 +76,6 @@ def main(args=None): sound_player_node.destroy_node() rclpy.shutdown() + if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/mini_pupper_music/setup.py b/mini_pupper_music/setup.py index 6d4ba1e..8df903c 100644 --- a/mini_pupper_music/setup.py +++ b/mini_pupper_music/setup.py @@ -9,7 +9,8 @@ version='1.0.0', packages=find_packages(exclude=['test']), data_files=[ - ('share/ament_index/resource_index/packages', ['resource/' + package_name]), + ('share/ament_index/resource_index/packages', + ['resource/' + package_name]), ('share/' + package_name, ['package.xml']), ('share/' + package_name + '/resource', glob('resource/*')), (os.path.join('share', package_name), glob('launch/*.launch.py')),