public final class AudioUtils extends Object
public static AudioInputStream createAudioStream(AudioFormat format, byte[] data)
AudioInputStream from an AudioFormat and the audio data.format - Expected to be PCM.public static AudioInputStream createAudioStream(AudioFormat format, ByteArrayInputStream data)
public static AudioInputStream createAudioStream(InputStream stream) throws UnsupportedAudioFileException, IOException
AudioInputStream from a InputStream.
This is to work around a bug in AudioSystem
which may return AudioInputStream with a wrong AudioInputStream.getFrameLength().public static Duration getDuration(AudioInputStream stream)
IllegalArgumentException - if format is not PCM encoded with specified frame rate.public static Duration getDuration(AudioFormat format, int bytes)
IllegalArgumentException - if format is not PCM encoded with specified frame rate
and frame size.public static long getLengthInFrames(PCMAudioFormat format, Duration duration)
public static AudioInputStream concat(Iterable<AudioInputStream> streams)
AudioInputStream into a single AudioInputStream.streams - Must be streams with the same (PCM) audio format.public static Iterable<AudioInputStream> split(AudioInputStream stream, Duration... splitPoints)
AudioInputStream into a sequence of AudioInputStream.stream - Must be PCM encoded. AudioInputStream.getFrameLength() must return the
actual number of available frames in the stream.splitPoints - Are relative to the beginning of the stream.IllegalArgumentException - if a negative split point is provided, a split point exceeds
the total length of the input stream, or a split point is not
greater than or equal to the preceding split point ,and also
if the audio format is not PCM encoded with specified frame
rate and frame size.public static Iterable<AudioInputStream> split(AudioInputStream stream, long... splitPoints)
public static AudioInputStream createSilence(PCMAudioFormat format, Duration duration)
duration - must not be negativenull if duration is too shortpublic static AudioInputStream createSilence(AudioFormat format, long frames)
format - must be PCM encodedframes - must not be negativenull if frames is 0public static AudioInputStream convertAudioStream(AudioFormat newFormat, AudioInputStream stream)
public static boolean isPCM(AudioFormat format)
Copyright © 2010–2025 The DAISY Consortium. All rights reserved.