from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
import os
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    """Launch the TTS service node."""
    package_dir = get_package_share_directory("saltybot_tts_service")
    config_path = os.path.join(package_dir, "config", "tts_service_params.yaml")

    # Declare launch arguments
    voice_model_arg = DeclareLaunchArgument(
        "voice_model",
        default_value="/models/piper/en_US-lessac-medium.onnx",
        description="Path to Piper voice model (ONNX)",
    )

    audio_device_arg = DeclareLaunchArgument(
        "audio_device",
        default_value="Jabra",
        description="ALSA audio device name or alias",
    )

    # TTS service node
    tts_node = Node(
        package="saltybot_tts_service",
        executable="tts_service_node",
        name="tts_service",
        parameters=[
            config_path,
            {"voice_model_path": LaunchConfiguration("voice_model")},
            {"audio_device": LaunchConfiguration("audio_device")},
        ],
        respawn=False,
        output="screen",
    )

    return LaunchDescription(
        [
            voice_model_arg,
            audio_device_arg,
            tts_node,
        ]
    )
