Package org.openhab.core.audio.transcode
Class AudioTranscoder
java.lang.Object
org.openhab.core.audio.transcode.AudioTranscoder
Utility class for transcoding
AudioStreams using the Java Sound API.
Supports transcoding between AudioFormat.WAV, AudioFormat.PCM_SIGNED,
AudioFormat.FLAC, and all PCM variations supported by the Java Sound API
(signed/unsigned PCM, A-law, μ-law), including sample rate resampling, bit-depth
conversion, and endianness changes.
- Author:
- Florian Hotze - Initial contribution
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanTranscode(@Nullable AudioFormat sourceFormat, @Nullable AudioFormat targetFormat) Checks whether this transcoder can transcode from the source format to the target format.static Set<AudioFormat> Gets the set of general audio formats supported for decoding (reading as source stream).static Set<AudioFormat> Gets the set of general audio formats supported for encoding (writing as target stream).static booleanisSourceSupported(@Nullable AudioFormat format) Checks if the given audio format can be decoded from a source stream.static booleanisSupported(@Nullable AudioFormat format) Checks if the given audio format is supported by this transcoder (either for decoding or encoding).static booleanisTargetSupported(@Nullable AudioFormat format) Checks if the given audio format can be encoded to a target stream.static AudioStreamtranscode(AudioStream source, AudioFormat targetFormat) Transcodes the given audio stream to the requested target format.static AudioStreamtranscode(AudioStream source, AudioFormat targetFormat, boolean requireSizeable) Transcodes the given audio stream to the requested target format.static AudioStreamtranscode(AudioStream source, AudioFormat targetFormat, Set<Class<? extends AudioStream>> supportedStreams) Transcodes the given audio stream to the requested target format, taking into account supported stream types.static AudioStreamtranscodeToSupported(AudioStream source, Set<AudioFormat> candidateFormats) Transcodes the audio stream to a format supported by candidateFormats (e.g. from an AudioSink).static AudioStreamtranscodeToSupported(AudioStream source, Set<AudioFormat> candidateFormats, boolean requireSizeable) Transcodes the audio stream to a format supported by candidateFormats (e.g. from an AudioSink).static AudioStreamtranscodeToSupported(AudioStream source, Set<AudioFormat> candidateFormats, Set<Class<? extends AudioStream>> supportedStreams) Transcodes the audio stream to a format and stream type supported by candidateFormats and supportedStreams (e.g.
-
Field Details
-
SUPPORTED_SOURCE_FORMATS
-
SUPPORTED_TARGET_FORMATS
-
-
Method Details
-
getSupportedSourceFormats
Gets the set of general audio formats supported for decoding (reading as source stream).- Returns:
- supported source audio formats
-
getSupportedTargetFormats
Gets the set of general audio formats supported for encoding (writing as target stream).- Returns:
- supported target audio formats
-
isSupported
Checks if the given audio format is supported by this transcoder (either for decoding or encoding).- Parameters:
format- the format to check- Returns:
- true if the format is supported, false otherwise
-
isSourceSupported
Checks if the given audio format can be decoded from a source stream.- Parameters:
format- the format to check- Returns:
- true if the format can be decoded, false otherwise
-
isTargetSupported
Checks if the given audio format can be encoded to a target stream.- Parameters:
format- the format to check- Returns:
- true if the format can be encoded, false otherwise
-
canTranscode
public static boolean canTranscode(@Nullable AudioFormat sourceFormat, @Nullable AudioFormat targetFormat) Checks whether this transcoder can transcode from the source format to the target format.- Parameters:
sourceFormat- the source formattargetFormat- the target format- Returns:
- true if transcoding is possible, false otherwise
-
transcode
public static AudioStream transcode(AudioStream source, AudioFormat targetFormat) throws AudioTranscodingException Transcodes the given audio stream to the requested target format.Favors streaming via
PipedAudioStreamfor lower latency without disk buffering.- Parameters:
source- the audio stream to transcodetargetFormat- the desired target format- Returns:
- a new audio stream in the requested target format
- Throws:
AudioTranscodingException- if transcoding fails or formats are unsupported
-
transcode
public static AudioStream transcode(AudioStream source, AudioFormat targetFormat, Set<Class<? extends AudioStream>> supportedStreams) throws AudioTranscodingException Transcodes the given audio stream to the requested target format, taking into account supported stream types.- Parameters:
source- the audio stream to transcodetargetFormat- the desired target formatsupportedStreams- the set of stream classes supported by the consumer/sink- Returns:
- a new audio stream in the requested target format
- Throws:
AudioTranscodingException- if transcoding fails or formats are unsupported
-
transcode
public static AudioStream transcode(AudioStream source, AudioFormat targetFormat, boolean requireSizeable) throws AudioTranscodingException Transcodes the given audio stream to the requested target format.- Parameters:
source- the audio stream to transcodetargetFormat- the desired target formatrequireSizeable- true to buffer to disk and return aSizeableAudioStream, false to stream via pipe- Returns:
- a new audio stream in the requested target format
- Throws:
AudioTranscodingException- if transcoding fails or formats are unsupported
-
transcodeToSupported
public static AudioStream transcodeToSupported(AudioStream source, Set<AudioFormat> candidateFormats) throws AudioTranscodingException Transcodes the audio stream to a format supported by candidateFormats (e.g. from an AudioSink).- Parameters:
source- the audio stream to transcodecandidateFormats- the acceptable target formats- Returns:
- an audio stream compatible with one of the candidateFormats
- Throws:
AudioTranscodingException- if no route to any candidate format exists or transcoding fails
-
transcodeToSupported
public static AudioStream transcodeToSupported(AudioStream source, Set<AudioFormat> candidateFormats, Set<Class<? extends AudioStream>> supportedStreams) throws AudioTranscodingException Transcodes the audio stream to a format and stream type supported by candidateFormats and supportedStreams (e.g. from an AudioSink).- Parameters:
source- the audio stream to transcodecandidateFormats- the acceptable target formatssupportedStreams- the set of stream classes supported by the consumer/sink- Returns:
- an audio stream compatible with one of the candidateFormats
- Throws:
AudioTranscodingException- if no route to any candidate format exists or transcoding fails
-
transcodeToSupported
public static AudioStream transcodeToSupported(AudioStream source, Set<AudioFormat> candidateFormats, boolean requireSizeable) throws AudioTranscodingException Transcodes the audio stream to a format supported by candidateFormats (e.g. from an AudioSink).- Parameters:
source- the audio stream to transcodecandidateFormats- the acceptable target formatsrequireSizeable- true to buffer to disk and return aSizeableAudioStream, false to stream via pipe- Returns:
- an audio stream compatible with one of the candidateFormats
- Throws:
AudioTranscodingException- if no route to any candidate format exists or transcoding fails
-