WavFileGenerator

org.llm4s.speech.io.WavFileGenerator

Eliminates code duplication in WAV file generation across the speech module. Provides centralized WAV file creation, format conversion, metadata validation, and temporary file management.

All generation entry points validate AudioMeta up front via validateMetadata so that invalid sample rates, channel counts, or bit depths fail fast with a descriptive WavError rather than producing a corrupt WAV file.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

sealed trait WavError extends LLMError

Attributes

Supertypes
trait LLMError
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
final case class WavGenerationFailed(message: String, context: Map[String, String]) extends WavError

Attributes

Supertypes
trait WavError
trait LLMError
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class WavSaveFailed(message: String, context: Map[String, String]) extends WavError

Attributes

Supertypes
trait WavError
trait LLMError
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def createJavaAudioFormat(meta: AudioMeta): AudioFormat

Create a Java AudioFormat from AudioMeta.

Create a Java AudioFormat from AudioMeta.

Attributes

def createTempWavFile(prefix: String): Result[Path]

Create a temporary WAV file with the given prefix.

Create a temporary WAV file with the given prefix.

Attributes

def createWavFromBytes(data: Array[Byte], meta: AudioMeta): Result[GeneratedAudio]

Create GeneratedAudio from raw bytes with metadata, validating the metadata first.

Create GeneratedAudio from raw bytes with metadata, validating the metadata first.

Attributes

def createWavHeader(dataSize: Int, meta: AudioMeta): Result[Array[Byte]]

Utility for creating WAV headers manually (advanced usage).

Utility for creating WAV headers manually (advanced usage).

Validates the metadata, then uses BinaryWriter typeclass instances for correct little-endian encoding. Returns a Result rather than throwing, per project convention.

Attributes

def managedTempWavFile(prefix: String): ManagedResource[Path]

Create a managed temporary WAV file that gets deleted automatically.

Create a managed temporary WAV file that gets deleted automatically.

Attributes

def readWavFile(path: Path): Result[GeneratedAudio]

Read a WAV file and return GeneratedAudio, parsing actual RIFF/WAV header fields.

Read a WAV file and return GeneratedAudio, parsing actual RIFF/WAV header fields.

The parsed metadata is validated via validateMetadata so that a malformed or non-PCM file is rejected with a descriptive error rather than yielding garbage metadata.

WAV header layout (little-endian): Offset 22: NumChannels (Short) Offset 24: SampleRate (Int) Offset 34: BitsPerSample (Short) Offset 44+: audio data

Attributes

def saveAsWav(audio: GeneratedAudio, path: Path): Result[Path]

Save GeneratedAudio as a WAV file using ManagedResource (eliminates duplication from AudioIO.saveWav).

Save GeneratedAudio as a WAV file using ManagedResource (eliminates duplication from AudioIO.saveWav).

The audio metadata is validated before writing.

Attributes

def saveRawPcmAsWav(data: Array[Byte], meta: AudioMeta, path: Path): Result[Path]

Save raw PCM data as a WAV file (eliminates duplication from AudioIO.saveRawPcm16).

Save raw PCM data as a WAV file (eliminates duplication from AudioIO.saveRawPcm16).

Metadata validation happens once inside saveAsWav to avoid double validation.

Attributes

Validate AudioMeta before it is used to generate or read a WAV file.

Validate AudioMeta before it is used to generate or read a WAV file.

Enforces that the sample rate is positive, the channel count is within [1,MaxChannels], and the bit depth is one of SupportedBitDepths.

Attributes

Returns

the unchanged meta on success, or a WavGenerationFailed describing the first violation

def writeToTempWav(data: Array[Byte], meta: AudioMeta, prefix: String): Result[Path]

Write audio data to a temporary WAV file and return the path (eliminates duplication in TTS implementations).

Write audio data to a temporary WAV file and return the path (eliminates duplication in TTS implementations).

Attributes

Concrete fields

val MaxChannels: Int

Maximum number of channels permitted (mono through 7.1 surround).

Maximum number of channels permitted (mono through 7.1 surround).

Attributes

val SupportedBitDepths: Set[Int]

Bit depths supported by this module's PCM WAV writer and reader.

Bit depths supported by this module's PCM WAV writer and reader.

Attributes