AudioDecoding

org.llm4s.speech.io.AudioDecoding
object AudioDecoding

The one step that turns an AudioInput into PCM and its format, shared by every speech-to-text backend (#3143), and the RIFF/WAVE reader under it (#3144).

The rule, for every engine:

  • Bytes that start with a RIFF/WAVE header are a WAV file. Its chunks are walked (a LIST, fact or other chunk before data, an extensible fmt chunk, the pad byte after an odd-sized chunk), and the format is read from fmt, never assumed.
  • Other BytesAudio and StreamAudio bytes are raw 16-bit little-endian PCM at the declared sampleRate and numChannels: what every TTS client returns in GeneratedAudio.data.
  • A FileAudio must be a WAV file to be decoded; a cloud engine that takes other containers (MP3, FLAC ...) uploads such a file as it is, through uploadBytes.

Decoded PCM is always 16-bit signed little-endian: 8-bit (unsigned), 24- and 32-bit integer and 32-bit float WAV data is converted, so the preprocessing steps, which work on 16-bit samples, see the right amplitudes.

Attributes

Source
AudioDecoding.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

final case class Pcm(data: Array[Byte], meta: AudioMeta)

16-bit signed little-endian PCM, interleaved, and its format (bitDepth is always 16).

16-bit signed little-endian PCM, interleaved, and its format (bitDepth is always 16).

Attributes

Source
AudioDecoding.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def decode(input: AudioInput): Result[Pcm]

The audio of input as 16-bit PCM, by the rule above.

The audio of input as 16-bit PCM, by the rule above.

Attributes

Source
AudioDecoding.scala
def isWav(bytes: Array[Byte]): Boolean

Whether bytes start with a RIFF/WAVE header.

Whether bytes start with a RIFF/WAVE header.

Attributes

Source
AudioDecoding.scala
def parseWav(bytes: Array[Byte]): Option[Result[Pcm]]

The PCM of a WAV file, or None when bytes is not one. A WAV whose fmt chunk is missing or truncated, has no data chunk, or holds a format other than integer PCM (8, 16, 24 or 32 bit) or 32-bit float is a Left naming what it found.

The PCM of a WAV file, or None when bytes is not one. A WAV whose fmt chunk is missing or truncated, has no data chunk, or holds a format other than integer PCM (8, 16, 24 or 32 bit) or 32-bit float is a Left naming what it found.

Attributes

Source
AudioDecoding.scala
def toWav(pcm: Pcm): Result[Array[Byte]]

pcm as a canonical 44-byte-header WAV file.

pcm as a canonical 44-byte-header WAV file.

Attributes

Source
AudioDecoding.scala

The bytes to upload to an engine that takes a container (a cloud API, the Whisper CLI): a FileAudio, or bytes that already are a WAV file, as they are; raw PCM wrapped in the WAV header it lacks, at its declared format.

The bytes to upload to an engine that takes a container (a cloud API, the Whisper CLI): a FileAudio, or bytes that already are a WAV file, as they are; raw PCM wrapped in the WAV header it lacks, at its declared format.

Attributes

Source
AudioDecoding.scala