Files
hivecore_robot_voice/launch/register_speaker.launch.py
2026-01-27 20:53:43 +08:00

55 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import SetEnvironmentVariable, RegisterEventHandler
from launch.event_handlers import OnProcessExit
from launch.actions import EmitEvent
from launch.events import Shutdown
import os
def generate_launch_description():
"""启动声纹注册节点需要ASR服务"""
# 获取interfaces包的install路径
interfaces_install_path = os.path.expanduser('~/ros_learn/hivecore_robot_interfaces/install')
# 设置AMENT_PREFIX_PATH确保能找到interfaces包的消息类型
ament_prefix_path = os.environ.get('AMENT_PREFIX_PATH', '')
if interfaces_install_path not in ament_prefix_path:
if ament_prefix_path:
ament_prefix_path = f'{ament_prefix_path}:{interfaces_install_path}'
else:
ament_prefix_path = interfaces_install_path
# ASR + 音频输入设备节点提供ASR和AudioData服务
asr_audio_node = Node(
package='robot_speaker',
executable='asr_audio_node',
name='asr_audio_node',
output='screen'
)
# 声纹注册节点
register_speaker_node = Node(
package='robot_speaker',
executable='register_speaker_node',
name='register_speaker_node',
output='screen'
)
# 当注册节点退出时,关闭整个 launch
register_exit_handler = RegisterEventHandler(
OnProcessExit(
target_action=register_speaker_node,
on_exit=[
EmitEvent(event=Shutdown(reason='注册完成,关闭所有节点'))
]
)
)
return LaunchDescription([
SetEnvironmentVariable('AMENT_PREFIX_PATH', ament_prefix_path),
asr_audio_node,
register_speaker_node,
register_exit_handler,
])