Class AudioFactory

java.lang.Object
ai.djl.modality.audio.AudioFactory
Direct Known Subclasses:
SampledAudioFactory

public abstract class AudioFactory extends Object
AudioFactory contains audio creation mechanism on top of different platforms like PC and Android. System will choose appropriate Factory based on the supported audio type.
  • Field Details

    • channels

      protected int channels
    • sampleRate

      protected int sampleRate
    • sampleFormat

      protected int sampleFormat
  • Constructor Details

    • AudioFactory

      public AudioFactory()
  • Method Details

    • newInstance

      public static AudioFactory newInstance()
      Constructs a new instance of AudioFactory.
      Returns:
      a new instance of AudioFactory
    • fromFile

      public abstract Audio fromFile(Path path) throws IOException
      Returns Audio from file.
      Parameters:
      path - the path to the audio
      Returns:
      Audio
      Throws:
      IOException - Audio not found or not readable
    • fromUrl

      public Audio fromUrl(URL url) throws IOException
      Returns Audio from URL.
      Parameters:
      url - the URL to load from
      Returns:
      Audio
      Throws:
      IOException - URL is not valid.
    • fromUrl

      public Audio fromUrl(String url) throws IOException
      Returns Audio from URL.
      Parameters:
      url - the String represent URL to load from
      Returns:
      Audio
      Throws:
      IOException - URL is not valid.
    • fromInputStream

      public abstract Audio fromInputStream(InputStream is) throws IOException
      Returns Audio from InputStream.
      Parameters:
      is - InputStream
      Returns:
      Audio
      Throws:
      IOException - image cannot be read from input stream.
    • fromData

      public Audio fromData(float[] data)
      Returns Audio from raw data.
      Parameters:
      data - the raw data in float array form.
      Returns:
      Audio
    • fromNDArray

      public Audio fromNDArray(NDArray array)
      Returns Audio from NDArray.
      Parameters:
      array - the NDArray with CHW format
      Returns:
      Audio
    • setChannels

      public AudioFactory setChannels(int channels)
      Sets the number of channels for AudioFactory to use.
      Parameters:
      channels - the number of channels for AudioFactory to use
      Returns:
      this factory
    • getChannels

      public int getChannels()
      Returns the channels of this factory.
      Returns:
      the channels of this factory
    • setSampleRate

      public AudioFactory setSampleRate(int sampleRate)
      Sets the sampleRate for AudioFactory to use.
      Parameters:
      sampleRate - the sampleRate for AudioFactory to use
      Returns:
      this factory
    • getSampleRate

      public int getSampleRate()
      Returns the sample rate.
      Returns:
      the sample rate in integer
    • setSampleFormat

      public AudioFactory setSampleFormat(int sampleFormat)
      Sets the audio sample format for AudioFactory to use.
      Parameters:
      sampleFormat - the sample format
      Returns:
      this factory.
    • getSampleFormat

      public int getSampleFormat()
      Returns the sample format name of the audio.
      Returns:
      the format name of the audio