"""ambient_sound.launch.py -- Launch the ambient sound classifier (Issue #252).

Usage:
  ros2 launch saltybot_social ambient_sound.launch.py
  ros2 launch saltybot_social ambient_sound.launch.py silence_db:=-45.0
"""

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


def generate_launch_description():
    pkg = get_package_share_directory("saltybot_social")
    cfg = os.path.join(pkg, "config", "ambient_sound_params.yaml")

    return LaunchDescription([
        DeclareLaunchArgument("window_s",    default_value="1.0",
                              description="Accumulation window (s)"),
        DeclareLaunchArgument("n_mels",      default_value="32",
                              description="Mel filterbank bands"),
        DeclareLaunchArgument("silence_db",  default_value="-40.0",
                              description="Silence energy threshold (dBFS)"),

        Node(
            package="saltybot_social",
            executable="ambient_sound_node",
            name="ambient_sound_node",
            output="screen",
            parameters=[
                cfg,
                {
                    "window_s":   LaunchConfiguration("window_s"),
                    "n_mels":     LaunchConfiguration("n_mels"),
                    "silence_db": LaunchConfiguration("silence_db"),
                },
            ],
        ),
    ])
