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
()
| 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). |
| 21 | func 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(omnivoiceSampleRate)) // sample rate |
| 32 | w(uint32(omnivoiceSampleRate * 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. |
no test coverage detected