MCPcopy
hub / github.com/mudler/LocalAI / wavHeader24k

Function wavHeader24k

backend/go/qwen3-tts-cpp/audio.go:21–38  ·  view source on GitHub ↗

wavHeader24k returns a 44-byte WAV header for a streaming 24 kHz mono 16-bit PCM stream, with placeholder (0xFFFFFFFF) sizes since the total length is unknown up front. Emitted as the first chunk of TTSStream so the HTTP layer receives a self-describing WAV (the gRPC TTSStream path never sets Messag

()

Source from the content-addressed store, hash-verified

19// receives a self-describing WAV (the gRPC TTSStream path never sets Message,
20// so the backend owns the header - see core/backend/tts.go:ModelTTSStream).
21func wavHeader24k() []byte {
22 var buf bytes.Buffer
23 w := func(v any) { _ = binary.Write(&buf, binary.LittleEndian, v) }
24 buf.WriteString("RIFF")
25 w(uint32(0xFFFFFFFF))
26 buf.WriteString("WAVE")
27 buf.WriteString("fmt ")
28 w(uint32(16)) // Subchunk1Size
29 w(uint16(1)) // PCM
30 w(uint16(1)) // mono
31 w(uint32(qwen3ttsSampleRate)) // sample rate
32 w(uint32(qwen3ttsSampleRate * 2)) // byte rate = SR * blockAlign
33 w(uint16(2)) // block align (16-bit mono)
34 w(uint16(16)) // bits per sample
35 buf.WriteString("data")
36 w(uint32(0xFFFFFFFF))
37 return buf.Bytes()
38}
39
40// floatToPCM16LE clamps each sample to [-1,1] and encodes it as little-endian
41// signed 16-bit PCM.

Callers 2

TTSStreamMethod · 0.70

Calls 2

wFunction · 0.50
WriteMethod · 0.45

Tested by

no test coverage detected