From 4f4c1f36150a059075bee96b476719f84eb9b4ef Mon Sep 17 00:00:00 2001 From: Yoshida Hiroshi Date: Fri, 27 Dec 2024 11:14:05 +0900 Subject: [PATCH] =?UTF-8?q?minimumTranscribedTime=20=E3=81=A8=20minimumCon?= =?UTF-8?q?fidenceScore=20=E3=81=AE=E4=B8=A1=E6=96=B9=E3=81=8C=E7=84=A1?= =?UTF-8?q?=E5=8A=B9=E3=81=AB=E8=A8=AD=E5=AE=9A=E3=81=95=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=AF=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=AB=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=84=E7=B5=90=E6=9E=9C=E3=82=92=E8=BF=94=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 3 ++ amazon_transcribe_handler.go | 9 ++++ amazon_transcribe_handler_test.go | 81 ++++++++++++++++++++++++++----- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0d40588..75c0103 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ ## develop +- [CHANGE] Amazon Transcribe 向けの minimum_confidence_score と minimum_transcribed_time が両方ともに無効(0)に設定されていた場合は、フィルタリングしない結果を返すように変更する + - @Hexa + ### misc - [CHANGE] GitHub Actions の ubuntu-latest を ubuntu-24.04 に変更する diff --git a/amazon_transcribe_handler.go b/amazon_transcribe_handler.go index 2cbbe6a..adc73cc 100644 --- a/amazon_transcribe_handler.go +++ b/amazon_transcribe_handler.go @@ -254,6 +254,15 @@ func contentFilterByConfidenceScore(config Config, item transcribestreamingservi func buildMessage(config Config, alt transcribestreamingservice.Alternative, isPartial bool) (string, bool) { var message string + + minimumTranscribedTime := config.MinimumTranscribedTime + minimumConfidenceScore := config.MinimumConfidenceScore + + // 両方無効の場合には全てのメッセージを返す + if (minimumTranscribedTime <= 0) && (minimumConfidenceScore <= 0) { + return *alt.Transcript, true + } + items := alt.Items includePronunciation := false diff --git a/amazon_transcribe_handler_test.go b/amazon_transcribe_handler_test.go index 1895f13..353714c 100644 --- a/amazon_transcribe_handler_test.go +++ b/amazon_transcribe_handler_test.go @@ -20,6 +20,58 @@ func TestBuildMessage(t *testing.T) { Ok bool } + t.Run("default", func(t *testing.T) { + testCases := []struct { + Name string + Config Config + Input Input + Expect Expect + }{ + { + Name: "minimumTranscribedTime == 0 && minimumConfidenceScore == 0", + Config: Config{ + MinimumTranscribedTime: 0, + MinimumConfidenceScore: 0, + }, + Input: Input{ + Alt: transcribestreamingservice.Alternative{ + Transcript: aws.String("filter is disabled"), + Items: []*transcribestreamingservice.Item{ + { + StartTime: aws.Float64(0), + EndTime: aws.Float64(1), + Confidence: aws.Float64(1), + Content: aws.String("test"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), + }, + { + StartTime: aws.Float64(0), + EndTime: aws.Float64(1), + Confidence: aws.Float64(1), + Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), + }, + }, + }, + IsPartial: false, + }, + Expect: Expect{ + Message: "filter is disabled", + Ok: true, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.Name, func(t *testing.T) { + actual, ok := buildMessage(tc.Config, tc.Input.Alt, tc.Input.IsPartial) + assert.Equal(t, tc.Expect.Ok, ok) + assert.Equal(t, tc.Expect.Message, actual) + }) + } + + }) + t.Run("minimumTranscribedTime", func(t *testing.T) { testCases := []struct { Name string @@ -31,21 +83,24 @@ func TestBuildMessage(t *testing.T) { Name: "minimumTranscribedTime is 0", Config: Config{ MinimumTranscribedTime: 0, + MinimumConfidenceScore: 0.1, }, Input: Input{ Alt: transcribestreamingservice.Alternative{ Items: []*transcribestreamingservice.Item{ { - 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), + Confidence: aws.Float64(1), + 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), + StartTime: aws.Float64(0), + EndTime: aws.Float64(0), + Confidence: aws.Float64(1), + Content: aws.String("data"), + Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, }, }, @@ -223,6 +278,7 @@ func TestBuildMessage(t *testing.T) { { Name: "minimumConfidenceScore is 0", Config: Config{ + MinimumTranscribedTime: 0.01, MinimumConfidenceScore: 0, }, Input: Input{ @@ -231,14 +287,14 @@ func TestBuildMessage(t *testing.T) { { Confidence: aws.Float64(0), StartTime: aws.Float64(0), - EndTime: aws.Float64(0), + EndTime: aws.Float64(1), Content: aws.String("test"), Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0), StartTime: aws.Float64(0), - EndTime: aws.Float64(0), + EndTime: aws.Float64(1), Content: aws.String("data"), Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, @@ -429,6 +485,7 @@ func TestBuildMessage(t *testing.T) { { Name: "minimumConfidenceScore is 0", Config: Config{ + MinimumTranscribedTime: 0.01, MinimumConfidenceScore: 0, }, Input: Input{ @@ -437,14 +494,14 @@ func TestBuildMessage(t *testing.T) { { Confidence: aws.Float64(0), StartTime: aws.Float64(0), - EndTime: aws.Float64(0), + EndTime: aws.Float64(1), Content: aws.String("test"), Type: aws.String(transcribestreamingservice.ItemTypePronunciation), }, { Confidence: aws.Float64(0), StartTime: aws.Float64(0), - EndTime: aws.Float64(0), + EndTime: aws.Float64(1), Content: aws.String("data"), Type: aws.String(transcribestreamingservice.ItemTypePronunciation), },