From 19ccb23b825bf5aac4ab746c70503565c2e5df1d Mon Sep 17 00:00:00 2001 From: Yoshida Hiroshi Date: Fri, 18 Oct 2024 14:41:17 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B5=90=E6=9E=9C=E3=81=AB=20timestamp=20?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- amazon_transcribe_handler.go | 7 +++++++ handler.go | 7 ++++--- speech_to_text_handler.go | 7 +++++++ test_handler.go | 7 +++++++ 4 files changed, 25 insertions(+), 3 deletions(-) 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