mirror of
https://github.com/mudler/LocalAI.git
synced 2025-12-30 01:50:23 -05:00
* feat(realtime): Initial Realtime API implementation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore: go mod tidy Signed-off-by: Richard Palethorpe <io@richiejp.com> * feat: Implement transcription only mode for realtime API Reduce the scope of the real time API for the initial realease and make transcription only mode functional. Signed-off-by: Richard Palethorpe <io@richiejp.com> * chore(build): Build backends on a separate layer to speed up core only changes Signed-off-by: Richard Palethorpe <io@richiejp.com> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Signed-off-by: Richard Palethorpe <io@richiejp.com> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package audio
|
|
|
|
// Copied from VoxInput
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
)
|
|
|
|
// WAVHeader represents the WAV file header (44 bytes for PCM)
|
|
type WAVHeader struct {
|
|
// RIFF Chunk (12 bytes)
|
|
ChunkID [4]byte
|
|
ChunkSize uint32
|
|
Format [4]byte
|
|
|
|
// fmt Subchunk (16 bytes)
|
|
Subchunk1ID [4]byte
|
|
Subchunk1Size uint32
|
|
AudioFormat uint16
|
|
NumChannels uint16
|
|
SampleRate uint32
|
|
ByteRate uint32
|
|
BlockAlign uint16
|
|
BitsPerSample uint16
|
|
|
|
// data Subchunk (8 bytes)
|
|
Subchunk2ID [4]byte
|
|
Subchunk2Size uint32
|
|
}
|
|
|
|
func NewWAVHeader(pcmLen uint32) WAVHeader {
|
|
header := WAVHeader{
|
|
ChunkID: [4]byte{'R', 'I', 'F', 'F'},
|
|
Format: [4]byte{'W', 'A', 'V', 'E'},
|
|
Subchunk1ID: [4]byte{'f', 'm', 't', ' '},
|
|
Subchunk1Size: 16, // PCM = 16 bytes
|
|
AudioFormat: 1, // PCM
|
|
NumChannels: 1, // Mono
|
|
SampleRate: 16000,
|
|
ByteRate: 16000 * 2, // SampleRate * BlockAlign (mono, 2 bytes per sample)
|
|
BlockAlign: 2, // 16-bit = 2 bytes per sample
|
|
BitsPerSample: 16,
|
|
Subchunk2ID: [4]byte{'d', 'a', 't', 'a'},
|
|
Subchunk2Size: pcmLen,
|
|
}
|
|
|
|
header.ChunkSize = 36 + header.Subchunk2Size
|
|
|
|
return header
|
|
}
|
|
|
|
func (h *WAVHeader) Write(writer io.Writer) error {
|
|
return binary.Write(writer, binary.LittleEndian, h)
|
|
}
|