Documentation
¶
Overview ¶
Package audio implements a small, deterministic PCM WAV boundary.
It reads uncompressed PCM16 in whatever rate and channel count a file happens to carry, and converts to the mono 16-bit form everything inside the runtime uses. Being strict about the container and permissive about the rate is deliberate: a fixture recorded at 44.1 kHz is a normal thing to be handed, and refusing it would push resampling onto every caller.
Index ¶
Constants ¶
const ( // OpenAIPCMSampleRate is the rate the Realtime wire uses for audio/pcm. OpenAIPCMSampleRate = uint32(24_000) // PCM16BytesPerSample is the size of one sample in one channel. PCM16BytesPerSample = uint16(2) MonoChannels = uint16(1) )
Variables ¶
This section is empty.
Functions ¶
func EncodeWAVMono16 ¶
EncodeWAVMono16 wraps mono PCM16LE in a canonical 44-byte WAV header.
Batch transcription endpoints take a container rather than raw samples, so something has to put the header on. It lives here because the decoder does too, and a writer that disagreed with its own reader would be found by a benchmark rather than by a test.
func GenerateFixture ¶
GenerateFixture writes a deterministic two-tone WAV.
It is the smallest thing that exercises the whole audio path with a known answer: two bursts separated by silence, at a fixed rate, hashing to a stable digest. Reproduction scripts assert that digest so a decode change that silently alters audio is caught by the fixture rather than by a benchmark result three steps later.
Types ¶
type Decoded ¶
type Decoded struct {
Metadata Metadata
// PCM16LE is mono, little-endian, at Metadata.SampleRateHz.
PCM16LE []byte
}
Decoded is mono PCM16 plus what it came from.
type Metadata ¶
type Metadata struct {
SampleRateHz uint32
Channels uint16
BitsPerSample uint16
SampleCount uint64
DataLengthBytes uint64
}
Metadata describes a decoded file.
func (Metadata) DurationNS ¶
DurationNS is the playing time of the decoded audio.
type PCM16MonoReader ¶
type PCM16MonoReader struct {
// contains filtered or unexported fields
}
PCM16MonoReader streams a decoded file in fixed frames.
func OpenPCM16Mono ¶
func OpenPCM16Mono(path string) (*PCM16MonoReader, error)
OpenPCM16Mono decodes a file for framed reading.
func (*PCM16MonoReader) Close ¶
func (reader *PCM16MonoReader) Close() error
Close exists so callers can treat the reader like a file handle.
func (*PCM16MonoReader) Metadata ¶
func (reader *PCM16MonoReader) Metadata() Metadata
Metadata describes the open file.