Package ai.djl.modality.audio
Class AudioFactory
java.lang.Object
ai.djl.modality.audio.AudioFactory
- Direct Known Subclasses:
SampledAudioFactory
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
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfromData(float[] data) ReturnsAudiofrom raw data.abstract AudioReturnsAudiofrom file.abstract AudioReturnsAudiofromInputStream.fromNDArray(NDArray array) ReturnsAudiofrom URL.ReturnsAudiofrom URL.intReturns the channels of this factory.intReturns the sample format name of the audio.intReturns the sample rate.static AudioFactoryConstructs a new instance ofAudioFactory.setChannels(int channels) Sets the number of channels forAudioFactoryto use.setSampleFormat(int sampleFormat) Sets the audio sample format forAudioFactoryto use.setSampleRate(int sampleRate) Sets the sampleRate forAudioFactoryto use.
-
Field Details
-
channels
protected int channels -
sampleRate
protected int sampleRate -
sampleFormat
protected int sampleFormat
-
-
Constructor Details
-
AudioFactory
public AudioFactory()
-
-
Method Details
-
newInstance
Constructs a new instance ofAudioFactory.- Returns:
- a new instance of
AudioFactory
-
fromFile
ReturnsAudiofrom file.- Parameters:
path- the path to the audio- Returns:
Audio- Throws:
IOException- Audio not found or not readable
-
fromUrl
ReturnsAudiofrom URL.- Parameters:
url- the URL to load from- Returns:
Audio- Throws:
IOException- URL is not valid.
-
fromUrl
ReturnsAudiofrom URL.- Parameters:
url- the String represent URL to load from- Returns:
Audio- Throws:
IOException- URL is not valid.
-
fromInputStream
ReturnsAudiofromInputStream.- Parameters:
is-InputStream- Returns:
Audio- Throws:
IOException- image cannot be read from input stream.
-
fromData
ReturnsAudiofrom raw data.- Parameters:
data- the raw data in float array form.- Returns:
Audio
-
fromNDArray
- Parameters:
array- the NDArray with CHW format- Returns:
Audio
-
setChannels
Sets the number of channels forAudioFactoryto use.- Parameters:
channels- the number of channels forAudioFactoryto use- Returns:
- this factory
-
getChannels
public int getChannels()Returns the channels of this factory.- Returns:
- the channels of this factory
-
setSampleRate
Sets the sampleRate forAudioFactoryto use.- Parameters:
sampleRate- the sampleRate forAudioFactoryto use- Returns:
- this factory
-
getSampleRate
public int getSampleRate()Returns the sample rate.- Returns:
- the sample rate in integer
-
setSampleFormat
Sets the audio sample format forAudioFactoryto 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
-