Skip to content

Commit

Permalink
Merge pull request #198 from shiguredo/feature/disable-filter
Browse files Browse the repository at this point in the history
minimumTranscribedTime と minimumConfidenceScore の両方が無効に設定されている場合はフィルタリングしない結果を返す
  • Loading branch information
Hexa authored Dec 27, 2024
2 parents 6b35538 + 20840f6 commit eb655d3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 に変更する
Expand Down
9 changes: 9 additions & 0 deletions amazon_transcribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 69 additions & 12 deletions amazon_transcribe_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
},
},
},
Expand Down Expand Up @@ -223,6 +278,7 @@ func TestBuildMessage(t *testing.T) {
{
Name: "minimumConfidenceScore is 0",
Config: Config{
MinimumTranscribedTime: 0.01,
MinimumConfidenceScore: 0,
},
Input: Input{
Expand All @@ -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),
},
Expand Down Expand Up @@ -429,6 +485,7 @@ func TestBuildMessage(t *testing.T) {
{
Name: "minimumConfidenceScore is 0",
Config: Config{
MinimumTranscribedTime: 0.01,
MinimumConfidenceScore: 0,
},
Input: Input{
Expand All @@ -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),
},
Expand Down
5 changes: 5 additions & 0 deletions config_example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ retry_interval_ms = 100
# aws の場合は IsPartial が false, gcp の場合は IsFinal が true の場合の最終的な結果のみを返す指定
final_result_only = true


# 採用する結果の信頼スコアの最小値です(aws 指定時のみ有効)
# minimum_confidence_score が 0.0 の場合は信頼スコアによるフィルタリングは無効です
# minimum_confidence_score = 0.0

# 採用する結果の最小発話期間(秒)です(aws 指定時のみ有効)
# minimum_transcribed_time が 0.0 の場合は発話期間によるフィルタリングは無効です
# minimum_transcribed_time = 0.0

# minimum_confidence_score と minimum_transcribed_time の両方が無効の場合はフィルタリングしません

# [aws]
aws_region = ap-northeast-1
# Partial-result stabilization の有効化です
Expand Down

0 comments on commit eb655d3

Please sign in to comment.