diff --git a/pkg/api/live/v1/default.go b/pkg/api/live/v1/default.go index 98f872be..67a7440e 100644 --- a/pkg/api/live/v1/default.go +++ b/pkg/api/live/v1/default.go @@ -95,6 +95,11 @@ func (dch DefaultCallbackHandler) Metadata(md *interfaces.MetadataResponse) erro return nil } +func (dch DefaultCallbackHandler) UtteranceEnd(ur *interfaces.UtteranceEndResponse) error { + fmt.Printf("\nUtteranceEnd \n") + return nil +} + func (dch DefaultCallbackHandler) Error(er *interfaces.ErrorResponse) error { var debugStr string if v := os.Getenv("DEEPGRAM_DEBUG"); v != "" { diff --git a/pkg/api/live/v1/interfaces/constants.go b/pkg/api/live/v1/interfaces/constants.go index 3e03362b..89840bdd 100644 --- a/pkg/api/live/v1/interfaces/constants.go +++ b/pkg/api/live/v1/interfaces/constants.go @@ -7,8 +7,9 @@ package interfaces // These are the message types that can be received from the live API const ( // message types - TypeMessageResponse string = "Results" - TypeMetadataResponse string = "Metadata" + TypeMessageResponse string = "Results" + TypeMetadataResponse string = "Metadata" + TypeUtteranceEndResponse string = "UtteranceEnd" // Error type TypeErrorResponse string = "Error" diff --git a/pkg/api/live/v1/interfaces/interfaces.go b/pkg/api/live/v1/interfaces/interfaces.go index 828bf0e6..dd25ca65 100644 --- a/pkg/api/live/v1/interfaces/interfaces.go +++ b/pkg/api/live/v1/interfaces/interfaces.go @@ -9,6 +9,7 @@ package interfaces type LiveMessageCallback interface { Message(mr *MessageResponse) error Metadata(md *MetadataResponse) error + UtteranceEnd(ur *UtteranceEndResponse) error Error(er *ErrorResponse) error // TODO: implement other conversation insights } diff --git a/pkg/api/live/v1/interfaces/types.go b/pkg/api/live/v1/interfaces/types.go index 2fc6647a..571312cb 100644 --- a/pkg/api/live/v1/interfaces/types.go +++ b/pkg/api/live/v1/interfaces/types.go @@ -70,6 +70,11 @@ type MetadataResponse struct { Type string `json:"type,omitempty"` } +// UtteranceEndResponse is the response from a live transcription +type UtteranceEndResponse struct { + Type string `json:"type,omitempty"` +} + // ErrorResponse is the response from a live transcription type ErrorResponse struct { Description string `json:"description"` diff --git a/pkg/api/live/v1/router.go b/pkg/api/live/v1/router.go index 60fbaa18..db3d5ec7 100644 --- a/pkg/api/live/v1/router.go +++ b/pkg/api/live/v1/router.go @@ -53,6 +53,8 @@ func (r *MessageRouter) Message(byMsg []byte) error { return r.MessageResponse(byMsg) case interfaces.TypeMetadataResponse: return r.MetadataResponse(byMsg) + case interfaces.TypeUtteranceEndResponse: + return r.UtteranceEndResponse(byMsg) default: return r.UnhandledMessage(byMsg) } @@ -121,6 +123,34 @@ func (r *MessageRouter) MetadataResponse(byMsg []byte) error { return nil } +func (r *MessageRouter) UtteranceEndResponse(byMsg []byte) error { + klog.V(6).Infof("router.UtteranceEnd ENTER\n") + + // trace debugging + r.printDebugMessages(5, "UtteranceEnd", byMsg) + + var ur interfaces.UtteranceEndResponse + err := json.Unmarshal(byMsg, &ur) + if err != nil { + klog.V(1).Infof("UtteranceEnd json.Unmarshal failed. Err: %v\n", err) + klog.V(6).Infof("router.UtteranceEnd LEAVE\n") + return err + } + + if r.callback != nil { + err := r.callback.UtteranceEnd(&ur) + if err != nil { + klog.V(1).Infof("callback.UtteranceEnd failed. Err: %v\n", err) + } else { + klog.V(5).Infof("callback.UtteranceEnd succeeded\n") + } + klog.V(6).Infof("router.UtteranceEnd LEAVE\n") + return err + } + + return nil +} + func (r *MessageRouter) ErrorResponse(byMsg []byte) error { klog.V(6).Infof("router.ErrorResponse ENTER\n")