Skip to content

Commit

Permalink
Amazon Transcribe からの結果の Results[].ResultId をクライアントに返すようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Mar 27, 2024
1 parent 0bda158 commit 34c66e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions amazon_transcribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func NewAmazonTranscribeHandler(config Config, channelID, connectionID string, s
type AwsResult struct {
ChannelID *string `json:"channel_id,omitempty"`
IsPartial *bool `json:"is_partial,omitempty"`
ResultID *string `json:"result_id,omitempty"`
TranscriptionResult
}

Expand All @@ -66,6 +67,11 @@ func (ar *AwsResult) WithIsPartial(isPartial bool) *AwsResult {
return ar
}

func (ar *AwsResult) WithResultID(resultID string) *AwsResult {
ar.ResultID = &resultID
return ar
}

func (ar *AwsResult) SetMessage(message string) *AwsResult {
ar.Message = message
return ar
Expand Down Expand Up @@ -155,6 +161,9 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader)
if at.Config.AwsResultChannelID {
result.WithChannelID(*res.ChannelId)
}
if at.Config.AwsResultResultID {
result.WithResultID(*res.ResultId)
}
for _, alt := range res.Alternatives {
var message string
if alt.Transcript != nil {
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Config struct {
// 変換結果に含める項目の有無の指定
AwsResultChannelID bool `ini:"aws_result_channel_id"`
AwsResultIsPartial bool `ini:"aws_result_is_partial"`
AwsResultResultID bool `ini:"aws_result_result_id"`

// Google Cloud Platform
GcpCredentialFile string `ini:"gcp_credential_file"`
Expand Down
4 changes: 4 additions & 0 deletions config_example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ aws_credential_file = ./credentials
aws_profile = default

# クライアントに送る変換結果の情報に付与する項目
# 結果に関連付いているオーディオのチャネルです
aws_result_channel_id = true
# セグメントが完了していないかどうかです
# aws_result_is_partial = true
# 結果の識別子です
# aws_result_result_id = true

# https://cloud.google.com/speech-to-text/docs/reference/rpc/google.cloud.speech.v1#streamingrecognitionconfig
# https://cloud.google.com/speech-to-text/docs/reference/rpc/google.cloud.speech.v1#recognitionconfig
Expand Down

0 comments on commit 34c66e1

Please sign in to comment.