From e8805ddd628691c737cb7cb4045982fc31209d7b Mon Sep 17 00:00:00 2001 From: Cullen SUN Date: Mon, 13 Nov 2023 00:08:06 +0800 Subject: [PATCH] use pygame to play sound --- mini_pupper_music/mini_pupper_music/music_server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mini_pupper_music/mini_pupper_music/music_server.py b/mini_pupper_music/mini_pupper_music/music_server.py index 85bac3d..04b21ef 100644 --- a/mini_pupper_music/mini_pupper_music/music_server.py +++ b/mini_pupper_music/mini_pupper_music/music_server.py @@ -18,7 +18,7 @@ import rclpy from rclpy.node import Node from mini_pupper_interfaces.srv import MusicCommand -from playsound import playsound +import pygame import threading import os from ament_index_python.packages import get_package_share_directory @@ -61,7 +61,9 @@ def play_sound_file(self, file_name): thread.start() def play_sound_in_background(self, sound_path): - playsound(sound_path) + pygame.init() + pygame.mixer.music.load(sound_path) + pygame.mixer.music.play() def main(args=None):