diff --git a/amazon_transcribe_handler.go b/amazon_transcribe_handler.go index eeb0d11..ee6b65a 100644 --- a/amazon_transcribe_handler.go +++ b/amazon_transcribe_handler.go @@ -6,6 +6,7 @@ import ( "errors" "io" "sync" + "time" "github.com/aws/aws-sdk-go/service/transcribestreamingservice" zlog "github.com/rs/zerolog/log" @@ -77,6 +78,11 @@ func (ar *AwsResult) SetMessage(message string) *AwsResult { return ar } +func (ar *AwsResult) SetTimestamp() *AwsResult { + ar.Timestamp = time.Now().UTC().Format(time.RFC3339Nano) + return ar +} + func (h *AmazonTranscribeHandler) UpdateRetryCount() int { defer h.mu.Unlock() h.mu.Lock() @@ -170,6 +176,7 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader) message = *alt.Transcript } result.SetMessage(message) + result.SetTimestamp() if err := encoder.Encode(result); err != nil { w.CloseWithError(err) return diff --git a/handler.go b/handler.go index cec4245..fa32c10 100644 --- a/handler.go +++ b/handler.go @@ -25,9 +25,10 @@ var ( ) type TranscriptionResult struct { - Message string `json:"message,omitempty"` - Reason string `json:"reason,omitempty"` - Type string `json:"type"` + Message string `json:"message,omitempty"` + Reason string `json:"reason,omitempty"` + Type string `json:"type"` + Timestamp string `json:"timestamp"` } func NewSuzuErrorResponse(err error) TranscriptionResult { diff --git a/speech_to_text_handler.go b/speech_to_text_handler.go index 5c85fd6..4a50034 100644 --- a/speech_to_text_handler.go +++ b/speech_to_text_handler.go @@ -8,6 +8,7 @@ import ( "io" "strings" "sync" + "time" zlog "github.com/rs/zerolog/log" @@ -73,6 +74,11 @@ func (gr *GcpResult) SetMessage(message string) *GcpResult { return gr } +func (gr *GcpResult) SetTimestamp() *GcpResult { + gr.Timestamp = time.Now().UTC().Format(time.RFC3339Nano) + return gr +} + func (h *SpeechToTextHandler) UpdateRetryCount() int { defer h.mu.Unlock() h.mu.Lock() @@ -240,6 +246,7 @@ func (h *SpeechToTextHandler) Handle(ctx context.Context, reader io.Reader) (*io } transcript := alternative.Transcript result.SetMessage(transcript) + result.SetTimestamp() if err := encoder.Encode(result); err != nil { w.CloseWithError(err) return diff --git a/test_handler.go b/test_handler.go index e264439..d616660 100644 --- a/test_handler.go +++ b/test_handler.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "sync" + "time" zlog "github.com/rs/zerolog/log" ) @@ -55,6 +56,11 @@ func NewTestResult(channelID, message string) TestResult { } } +func (tr *TestResult) SetTimestamp() *TestResult { + tr.Timestamp = time.Now().UTC().Format(time.RFC3339Nano) + return tr +} + func (h *TestHandler) UpdateRetryCount() int { defer h.mu.Unlock() h.mu.Lock() @@ -114,6 +120,7 @@ func (h *TestHandler) Handle(ctx context.Context, reader io.Reader) (*io.PipeRea return } } else { + result.SetTimestamp() if err := encoder.Encode(result); err != nil { w.CloseWithError(err) return