diff --git a/amazon_transcribe_handler.go b/amazon_transcribe_handler.go index d34ac7c..8870772 100644 --- a/amazon_transcribe_handler.go +++ b/amazon_transcribe_handler.go @@ -206,13 +206,13 @@ func contentFilterByTranscribedTime(config Config, item transcribestreamingservi return true } - // StartTime または EndTime が nil の場合はフィルタリングしない - if (item.StartTime == nil) || (item.EndTime == nil) { + // 句読点の場合はフィルタリングしない + if *item.Type == transcribestreamingservice.ItemTypePunctuation { return true } - // 発話時間が 0 の場合はフィルタリングしない(句読点を想定) - if *item.EndTime == *item.StartTime { + // StartTime または EndTime が nil の場合はフィルタリングしない + if (item.StartTime == nil) || (item.EndTime == nil) { return true } @@ -233,6 +233,11 @@ func contentFilterByConfidenceScore(config Config, item transcribestreamingservi return true } + // 句読点の場合はフィルタリングしない + if *item.Type == transcribestreamingservice.ItemTypePunctuation { + return true + } + // Confidence が nil の場合はフィルタリングしない if item.Confidence == nil { return true diff --git a/amazon_transcribe_handler_test.go b/amazon_transcribe_handler_test.go index a88e44f..eb7aeec 100644 --- a/amazon_transcribe_handler_test.go +++ b/amazon_transcribe_handler_test.go @@ -39,11 +39,13 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -67,16 +69,19 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.00), EndTime: aws.Float64(1.03), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { StartTime: aws.Float64(1.03), EndTime: aws.Float64(1.04), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { StartTime: aws.Float64(1.04), EndTime: aws.Float64(1.06), Content: aws.String("0"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -100,16 +105,19 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.00), EndTime: aws.Float64(1.01), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { StartTime: aws.Float64(1.01), EndTime: aws.Float64(1.02), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { StartTime: aws.Float64(1.02), EndTime: aws.Float64(1.03), Content: aws.String("0"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -133,16 +141,19 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.00), EndTime: aws.Float64(1.019), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { StartTime: aws.Float64(1.019), EndTime: aws.Float64(1.038), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { StartTime: aws.Float64(1.038), EndTime: aws.Float64(1.057), Content: aws.String("0"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -166,17 +177,19 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.00), EndTime: aws.Float64(1.02), Content: aws.String("テスト"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { - // 句読点は StartTime と EndTime が同じ StartTime: aws.Float64(1.02), EndTime: aws.Float64(1.02), Content: aws.String("、"), + Type: aws.String(transcribestreamingservice.ItemTypePunctuation), }, { StartTime: aws.Float64(1.02), EndTime: aws.Float64(1.04), Content: aws.String("データ"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -220,12 +233,14 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -250,18 +265,21 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.11), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("1"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -286,18 +304,21 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.1), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.1), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("1"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -322,18 +343,21 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.09), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.09), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("1"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -358,6 +382,7 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.0), EndTime: aws.Float64(1.02), Content: aws.String("テスト"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { // 句読点は Confidence は nil @@ -365,12 +390,14 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.02), EndTime: aws.Float64(1.02), Content: aws.String("、"), + Type: aws.String(transcribestreamingservice.ItemTypePunctuation), }, { Confidence: aws.Float64(0.2), StartTime: aws.Float64(1.02), EndTime: aws.Float64(1.04), Content: aws.String("データ"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -412,12 +439,14 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -442,18 +471,21 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.11), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("1"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -478,18 +510,21 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.1), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.1), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("1"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -514,18 +549,21 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.09), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0.09), StartTime: aws.Float64(0), EndTime: aws.Float64(0), Content: aws.String("1"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -550,6 +588,7 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.0), EndTime: aws.Float64(1.02), Content: aws.String("テスト"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { // 句読点は Confidence は nil @@ -557,12 +596,14 @@ func TestBuildMessage(t *testing.T) { StartTime: aws.Float64(1.02), EndTime: aws.Float64(1.02), Content: aws.String("、"), + Type: aws.String(transcribestreamingservice.ItemTypePunctuation), }, { Confidence: aws.Float64(0.2), StartTime: aws.Float64(1.02), EndTime: aws.Float64(1.04), Content: aws.String("データ"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, },