Package ai.djl.modality.audio
Class AudioFactory
- java.lang.Object
-
- ai.djl.modality.audio.AudioFactory
-
- Direct Known Subclasses:
SampledAudioFactory
public abstract class AudioFactory extends java.lang.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 Summary
Fields Modifier and Type Field Description protected int
channels
protected int
sampleFormat
protected int
sampleRate
-
Constructor Summary
Constructors Constructor Description AudioFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Audio
fromData(float[] data)
ReturnsAudio
from raw data.abstract Audio
fromFile(java.nio.file.Path path)
ReturnsAudio
from file.abstract Audio
fromInputStream(java.io.InputStream is)
ReturnsAudio
fromInputStream
.Audio
fromNDArray(NDArray array)
Audio
fromUrl(java.lang.String url)
ReturnsAudio
from URL.Audio
fromUrl(java.net.URL url)
ReturnsAudio
from URL.int
getChannels()
Returns the channels of this factory.int
getSampleFormat()
Returns the sample format name of the audio.int
getSampleRate()
Returns the sample rate.static AudioFactory
newInstance()
Constructs a new instance ofAudioFactory
.AudioFactory
setChannels(int channels)
Sets the number of channels forAudioFactory
to use.AudioFactory
setSampleFormat(int sampleFormat)
Sets the audio sample format forAudioFactory
to use.AudioFactory
setSampleRate(int sampleRate)
Sets the sampleRate forAudioFactory
to use.
-
-
-
Method Detail
-
newInstance
public static AudioFactory newInstance()
Constructs a new instance ofAudioFactory
.- Returns:
- a new instance of
AudioFactory
-
fromFile
public abstract Audio fromFile(java.nio.file.Path path) throws java.io.IOException
ReturnsAudio
from file.- Parameters:
path
- the path to the audio- Returns:
Audio
- Throws:
java.io.IOException
- Audio not found or not readable
-
fromUrl
public Audio fromUrl(java.net.URL url) throws java.io.IOException
ReturnsAudio
from URL.- Parameters:
url
- the URL to load from- Returns:
Audio
- Throws:
java.io.IOException
- URL is not valid.
-
fromUrl
public Audio fromUrl(java.lang.String url) throws java.io.IOException
ReturnsAudio
from URL.- Parameters:
url
- the String represent URL to load from- Returns:
Audio
- Throws:
java.io.IOException
- URL is not valid.
-
fromInputStream
public abstract Audio fromInputStream(java.io.InputStream is) throws java.io.IOException
ReturnsAudio
fromInputStream
.- Parameters:
is
-InputStream
- Returns:
Audio
- Throws:
java.io.IOException
- image cannot be read from input stream.
-
fromData
public Audio fromData(float[] data)
ReturnsAudio
from raw data.- Parameters:
data
- the raw data in float array form.- Returns:
Audio
-
fromNDArray
public Audio fromNDArray(NDArray array)
- Parameters:
array
- the NDArray with CHW format- Returns:
Audio
-
setChannels
public AudioFactory setChannels(int channels)
Sets the number of channels forAudioFactory
to use.- Parameters:
channels
- the number of channels forAudioFactory
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 forAudioFactory
to use.- Parameters:
sampleRate
- the sampleRate forAudioFactory
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 forAudioFactory
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
-
-