Class AudioDevice

java.lang.Object
uno.anahata.asi.toolkit.audio.AudioDevice

public class AudioDevice extends Object
Represents a stable, model-agnostic descriptor for an audio device.

This class is the authoritative way to identify and interact with hardware mixers. It provides static discovery and instance-level hardware binding (opening lines) to ensure consistency across the model and UI.

  • Field Details

    • DEFAULT_FORMAT

      public static final AudioFormat DEFAULT_FORMAT
      Default format for recording (16kHz, 16-bit, Mono) - Optimized for speech.
    • PLAYBACK_FORMAT

      public static final AudioFormat PLAYBACK_FORMAT
      Default format for playback (44.1kHz, 16-bit, Stereo) - CD Quality.
    • id

      private String id
      The unique identifier for the device, derived from hardware metadata.
    • name

      private String name
      The human-readable name of the device.
    • vendor

      private String vendor
      The vendor of the device.
    • description

      private String description
      A detailed description of the device.
    • type

      private AudioDevice.Type type
      The type of device (INPUT or OUTPUT).
    • defaultLine

      private boolean defaultLine
      Whether this device is the system's default line.
  • Constructor Details

    • AudioDevice

      public AudioDevice()
  • Method Details

    • fromMixerInfo

      public static AudioDevice fromMixerInfo(Mixer.Info info, AudioDevice.Type type)
      Factory method to create an AudioDevice from a Mixer.Info and a type.
      Parameters:
      info - The mixer info.
      type - The device type.
      Returns:
      A new AudioDevice instance.
    • generateStableId

      public static String generateStableId(Mixer.Info info)
      Generates a stable, hash-based ID for a mixer.
      Parameters:
      info - The mixer info.
      Returns:
      A stable ID string.
    • listAvailableDevices

      public static List<AudioDevice> listAvailableDevices()
      Lists all available audio devices that support data lines (Source/Target).
      Returns:
      A list of AudioDevice descriptors.
    • listAvailableDevices

      public static List<AudioDevice> listAvailableDevices(AudioDevice.Type type)
      Lists available audio devices of a specific type.
      Parameters:
      type - The desired device type.
      Returns:
      A filtered list of AudioDevice descriptors.
    • findDevice

      public static AudioDevice findDevice(AudioDevice.Type type, String id)
      Finds a specific audio device by its unique ID and type.
      Parameters:
      type - The device type.
      id - The device identifier.
      Returns:
      The AudioDevice, or null if not found.
    • getOutputLine

      public SourceDataLine getOutputLine(AudioFormat format) throws LineUnavailableException
      Resolves an output line (SourceDataLine) for this device and a format.
      Parameters:
      format - The desired audio format.
      Returns:
      A SourceDataLine instance.
      Throws:
      LineUnavailableException - if the line is already in use.
    • getInputLine

      public TargetDataLine getInputLine(AudioFormat format) throws LineUnavailableException
      Resolves an input line (TargetDataLine) for this device and a format.

      If the configured device mixer is unavailable or disconnected, automatically falls back to the system default input line.

      Parameters:
      format - The desired audio format.
      Returns:
      A TargetDataLine instance.
      Throws:
      LineUnavailableException - if no audio line is available.
    • getMixerInfo

      public Mixer.Info getMixerInfo()
      Resolves this descriptor back to a live JRE Mixer.Info.
      Returns:
      The Mixer.Info, or null if the device is no longer present.
    • toMarkdown

      public String toMarkdown()
      Returns a rich Markdown representation of the device for the AI model.
      Returns:
      The markdown string.
    • toString

      public String toString()
      Returns the human-friendly name for UI components.
      Overrides:
      toString in class Object
      Returns:
      the human-friendly name of this audio device.