Skip to content

Commit

Permalink
句読点の場合の処理を修正する
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Dec 20, 2024
1 parent 0748eb8 commit b06f498
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
13 changes: 9 additions & 4 deletions amazon_transcribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
43 changes: 42 additions & 1 deletion amazon_transcribe_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -358,19 +382,22 @@ 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
Confidence: nil,
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),
},
},
},
Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand All @@ -550,19 +588,22 @@ 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
Confidence: nil,
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),
},
},
},
Expand Down

0 comments on commit b06f498

Please sign in to comment.