Skip to content

Commit

Permalink
Merge branch 'release/2024.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexa committed Feb 22, 2024
2 parents cc53a60 + 3c65490 commit 4260b46
Show file tree
Hide file tree
Showing 14 changed files with 369 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Release
run: |
ghr -t "${{ secrets.GITHUB_TOKEN }}" -u "${{ github.repository_owner }}" -r "suzu" --replace "${GITHUB_REF##*/}" dist/
ghr -t "${{ secrets.GITHUB_TOKEN }}" -u "${{ github.repository_owner }}" -r "suzu" --replace -n "${GITHUB_REF##*/}" -draft "${GITHUB_REF##*/}" dist/
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

## develop


## 2024.1.0

- [UPDATE] go.mod の Go のバージョンを 1.22.0 にあげる
- @voluntas
- [CHANGE] サービス接続時にエラーになった場合は、Body が空のレスポンスを返すように変更する
- @Hexa
- [CHANGE] サービス接続後にエラーになった場合は、{"type": "error", "reason": string} をクライアントへ送信するように変更する
- @Hexa
- [CHANGE] aws の再接続条件の exception から InternalFailureException を削除する
- @Hexa


## 2023.5.3

- [FIX] VERSION ファイルを tag のバージョンに修正する
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ sequenceDiagram
## ライセンス

```
Copyright 2022-2023, Hiroshi Yoshida (Original Author)
Copyright 2022-2023, Shiguredo Inc.
Copyright 2022-2024, Hiroshi Yoshida (Original Author)
Copyright 2022-2024, Shiguredo Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023.5.3
2024.1.0
9 changes: 9 additions & 0 deletions amazon_transcribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/transcribestreamingservice"
)
Expand Down Expand Up @@ -95,6 +96,14 @@ func (at *AmazonTranscribe) Start(ctx context.Context, r io.Reader) (*transcribe

resp, err := client.StartStreamTranscriptionWithContext(ctx, &input)
if err != nil {
if reqErr, ok := err.(awserr.RequestFailure); ok {
code := reqErr.StatusCode()
message := reqErr.Message()
return nil, &SuzuError{
Code: code,
Message: message,
}
}
return nil, err
}

Expand Down
57 changes: 45 additions & 12 deletions amazon_transcribe_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package suzu
import (
"context"
"encoding/json"
"errors"
"io"

"github.com/aws/aws-sdk-go/service/transcribestreamingservice"
Expand Down Expand Up @@ -43,11 +44,10 @@ type AwsResult struct {
TranscriptionResult
}

func NewAwsResult(err error) AwsResult {
func NewAwsResult() AwsResult {
return AwsResult{
TranscriptionResult: TranscriptionResult{
Type: "aws",
Error: err,
Type: "aws",
},
}
}
Expand All @@ -62,18 +62,26 @@ func (ar *AwsResult) WithIsPartial(isPartial bool) *AwsResult {
return ar
}

func (ar *AwsResult) SetMessage(message string) *AwsResult {
ar.Message = message
return ar
}

func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader) (*io.PipeReader, error) {
at := NewAmazonTranscribe(h.Config, h.LanguageCode, int64(h.SampleRate), int64(h.ChannelCount))

oggReader, oggWriter := io.Pipe()
go func() {
defer oggWriter.Close()
if err := opus2ogg(ctx, reader, oggWriter, h.SampleRate, h.ChannelCount, h.Config); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
if !errors.Is(err, io.EOF) {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}

oggWriter.CloseWithError(err)
return
}
Expand All @@ -99,6 +107,13 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader)
case *transcribestreamingservice.TranscriptEvent:
if h.OnResultFunc != nil {
if err := h.OnResultFunc(ctx, w, h.ChannelID, h.ConnectionID, h.LanguageCode, e.Transcript.Results); err != nil {
if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}
w.CloseWithError(err)
return
}
Expand All @@ -111,7 +126,7 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader)
}
}

result := NewAwsResult(nil)
result := NewAwsResult()
if at.Config.AwsResultIsPartial {
result.WithIsPartial(*res.IsPartial)
}
Expand All @@ -123,7 +138,7 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader)
if alt.Transcript != nil {
message = *alt.Transcript
}
result.Message = message
result.SetMessage(message)
if err := encoder.Encode(result); err != nil {
w.CloseWithError(err)
return
Expand All @@ -140,16 +155,34 @@ func (h *AmazonTranscribeHandler) Handle(ctx context.Context, reader io.Reader)
if err := stream.Err(); err != nil {
// 復帰が不可能なエラー以外は再接続を試みる
switch err.(type) {
case *transcribestreamingservice.LimitExceededException,
*transcribestreamingservice.InternalFailureException:
case *transcribestreamingservice.LimitExceededException:
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()

// リトライしない設定の場合はクライアントにエラーを返し、再度接続するかはクライアント側で判断する
if !*at.Config.Retry {
if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}
}

err = ErrServerDisconnected
default:
// 再接続を想定している以外のエラーの場合はクライアントにエラーを返し、再度接続するかはクライアント側で判断する
if err := encoder.Encode(NewSuzuErrorResponse(err)); err != nil {
zlog.Error().
Err(err).
Str("channel_id", h.ChannelID).
Str("connection_id", h.ConnectionID).
Send()
}
}

w.CloseWithError(err)
Expand Down
10 changes: 10 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package suzu

type SuzuError struct {
Code int
Message string
}

func (e *SuzuError) Error() string {
return e.Message
}
42 changes: 21 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
module github.com/shiguredo/suzu

go 1.21.5
go 1.22.0

require (
cloud.google.com/go/speech v1.21.0
github.com/aws/aws-sdk-go v1.49.16
cloud.google.com/go/speech v1.21.1
github.com/aws/aws-sdk-go v1.50.20
github.com/labstack/echo-contrib v0.15.0
github.com/labstack/echo/v4 v4.11.4
github.com/pion/randutil v0.1.0
github.com/pion/rtp v1.8.3
github.com/rs/zerolog v1.31.0
github.com/rs/zerolog v1.32.0
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/net v0.19.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/net v0.21.0
golang.org/x/sync v0.6.0
google.golang.org/api v0.155.0
google.golang.org/grpc v1.60.1
google.golang.org/api v0.165.0
google.golang.org/grpc v1.61.1
google.golang.org/protobuf v1.32.0
gopkg.in/ini.v1 v1.67.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

require (
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -52,19 +52,19 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.15.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.0 // indirect
go.opentelemetry.io/otel/trace v1.23.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 4260b46

Please sign in to comment.