Class Audio

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class Audio extends AnahataToolkit
The definitive core toolkit for audio operations.

This toolkit is autonomous: it manages its own state for selected devices and implements self-healing defaults on initialization and session restoration.

  • Field Details

    • selectedInputDevice

      private AudioDevice selectedInputDevice
      The selected audio input device for this session.
    • selectedOutputDevice

      private AudioDevice selectedOutputDevice
      The selected audio output device for this session.
  • Constructor Details

    • Audio

      public Audio()
  • Method Details

    • initialize

      public void initialize()
      Performs initial setup for a newly created toolkit instance.

      This method is called exactly once by the ToolManager after the toolkit has been instantiated and registered. It provides a clean hook for toolkits to perform one-time initialization logic that requires the tool environment to be fully configured, such as scanning for project instructions or registering default resources.

      Auto-discovers and selects system hardware defaults on startup.

      Overrides:
      initialize in class AnahataToolkit
    • rebind

      public void rebind()
      Rebinds the toolkit after deserialization.

      This method is called by the framework during session activation to restore transient state, reconnect listeners, or refresh cached project instances. It ensures the propertyChangeSupport is re-initialized.

      Verifies that restored hardware devices still exist on the host.

      Specified by:
      rebind in interface Rebindable
      Overrides:
      rebind in class AnahataToolkit
    • initInputLineFromDefault

      private void initInputLineFromDefault()
      Discovers and selects the system's default input hardware.
    • initOutputLineFromDefault

      private void initOutputLineFromDefault()
      Discovers and selects the system's default output hardware.
    • setSelectedInputDevice

      public void setSelectedInputDevice(AudioDevice device)
      Sets the selected input device and fires a property change event.
      Parameters:
      device - The device to select.
    • setSelectedOutputDevice

      public void setSelectedOutputDevice(AudioDevice device)
      Sets the selected output device and fires a property change event.
      Parameters:
      device - The device to select.
    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Populates the given RagMessage with dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).
      Parameters:
      ragMessage - The message to be augmented with context.
      Throws:
      Exception - if an error occurs during context generation.
    • selectRecordingDevice

      public String selectRecordingDevice(String deviceId)
      Selects a specific device for recording for the current session.
      Parameters:
      deviceId - The unique ID of the input device to select.
      Returns:
      a status message.
    • selectOutputDevice

      public String selectOutputDevice(String deviceId)
      Selects a specific device for playback for the current session.
      Parameters:
      deviceId - The unique ID of the output device to select.
      Returns:
      a status message.
    • record

      public String record(int durationSeconds, String deviceId) throws Exception
      Records audio from the selected input device for a specified duration.
      Parameters:
      durationSeconds - Duration of the recording in seconds.
      deviceId - Optional specific device ID (overrides session selection).
      Returns:
      A status message.
      Throws:
      Exception - if hardware access fails.
    • play

      public String play(String uri, String deviceId) throws Exception
      Plays an audio file from a URI on the selected output device.
      Parameters:
      uri - The URI string.
      deviceId - Optional specific device ID (overrides session selection).
      Returns:
      a status message.
      Throws:
      Exception - if playback fails.