feat: migrate from msgpack to protobuf (handler-base v1.0.0)
- Replace msgpack.Marshal with proto.Marshal - Update field names to proto convention (SessionId, SpeakerId) - Cast Sequence to int32 for proto compatibility
This commit is contained in:
24
main.go
24
main.go
@@ -20,7 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/config"
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/health"
|
||||
@@ -324,17 +324,17 @@ func main() {
|
||||
|
||||
if transcript != "" {
|
||||
result := &messages.STTTranscription{
|
||||
SessionID: sessionID,
|
||||
SessionId: sessionID,
|
||||
Transcript: transcript,
|
||||
Sequence: seq,
|
||||
Sequence: int32(seq),
|
||||
IsPartial: !complete,
|
||||
IsFinal: complete,
|
||||
Timestamp: time.Now().Unix(),
|
||||
SpeakerID: speakerID,
|
||||
SpeakerId: speakerID,
|
||||
HasVoiceActivity: hasVoice,
|
||||
State: state,
|
||||
}
|
||||
packed, _ := msgpack.Marshal(result)
|
||||
packed, _ := proto.Marshal(result)
|
||||
_ = nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed)
|
||||
slog.Info("published transcription", "session", sessionID, "seq", seq)
|
||||
}
|
||||
@@ -378,8 +378,8 @@ func main() {
|
||||
}
|
||||
sessionID := parts[3]
|
||||
|
||||
streamMsg, err := natsutil.Decode[messages.STTStreamMessage](natMsg.Data)
|
||||
if err != nil {
|
||||
var streamMsg messages.STTStreamMessage
|
||||
if err := natsutil.Decode(natMsg.Data, &streamMsg); err != nil {
|
||||
slog.Error("decode error", "error", err)
|
||||
return
|
||||
}
|
||||
@@ -391,8 +391,8 @@ func main() {
|
||||
if streamMsg.State != "" {
|
||||
buf.setState(streamMsg.State)
|
||||
}
|
||||
if streamMsg.SpeakerID != "" {
|
||||
buf.speakerID = streamMsg.SpeakerID
|
||||
if streamMsg.SpeakerId != "" {
|
||||
buf.speakerID = streamMsg.SpeakerId
|
||||
}
|
||||
sessionsMu.Lock()
|
||||
sessions[sessionID] = buf
|
||||
@@ -442,12 +442,12 @@ func main() {
|
||||
// Check for interrupt
|
||||
if buffer.checkInterrupt(streamMsg.Audio, enableInterrupt, audioLevelThreshold, interruptDuration) {
|
||||
interruptMsg := &messages.STTInterrupt{
|
||||
SessionID: sessionID,
|
||||
SessionId: sessionID,
|
||||
Type: "interrupt",
|
||||
Timestamp: time.Now().Unix(),
|
||||
SpeakerID: buffer.speakerID,
|
||||
SpeakerId: buffer.speakerID,
|
||||
}
|
||||
packed, _ := msgpack.Marshal(interruptMsg)
|
||||
packed, _ := proto.Marshal(interruptMsg)
|
||||
_ = nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed)
|
||||
slog.Info("published interrupt", "session", sessionID)
|
||||
buffer.setState(stateListening)
|
||||
|
||||
Reference in New Issue
Block a user