Skip to content

Commit

Permalink
結果に timestamp を追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Oct 18, 2024
1 parent dd4fff8 commit 19ccb23
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions amazon_transcribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io"
"sync"
"time"

"github.com/aws/aws-sdk-go/service/transcribestreamingservice"
zlog "github.com/rs/zerolog/log"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions speech_to_text_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"strings"
"sync"
"time"

zlog "github.com/rs/zerolog/log"

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"sync"
"time"

zlog "github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 19ccb23

Please sign in to comment.