-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2189 from aws/feat-presign-polly
Add polly SynthesizeSpeech presigner
- Loading branch information
Showing
10 changed files
with
383 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "419f3a1b-33d8-4177-9c96-56a7d69c63e6", | ||
"type": "feature", | ||
"description": "Add support for polly SynthesizeSpeech GET request presigner", | ||
"modules": [ | ||
".", | ||
"service/polly" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package polly | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"github.com/aws/aws-sdk-go-v2/aws/protocol/query" | ||
"github.com/aws/smithy-go" | ||
"github.com/aws/smithy-go/middleware" | ||
smithyhttp "github.com/aws/smithy-go/transport/http" | ||
) | ||
|
||
// AddPresignSynthesizeSpeechMiddleware adds presignOpSynthesizeSpeechInput into middleware stack to | ||
// parse SynthesizeSpeechInput into request stream | ||
func AddPresignSynthesizeSpeechMiddleware(stack *middleware.Stack) error { | ||
return stack.Serialize.Insert(&presignOpSynthesizeSpeechInput{}, "Query:AsGetRequest", middleware.Before) | ||
} | ||
|
||
// presignOpSynthesizeSpeechInput encodes SynthesizeSpeechInput into url format | ||
// query string and put that into request stream for later presign-url build | ||
type presignOpSynthesizeSpeechInput struct { | ||
} | ||
|
||
func (*presignOpSynthesizeSpeechInput) ID() string { | ||
return "PresignSerializer" | ||
} | ||
|
||
func (m *presignOpSynthesizeSpeechInput) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( | ||
out middleware.SerializeOutput, metadata middleware.Metadata, err error, | ||
) { | ||
request, ok := in.Request.(*smithyhttp.Request) | ||
if !ok { | ||
return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)} | ||
} | ||
|
||
input, ok := in.Parameters.(*SynthesizeSpeechInput) | ||
_ = input | ||
if !ok { | ||
return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown input parameters type %T", in.Parameters)} | ||
} | ||
|
||
bodyWriter := bytes.NewBuffer(nil) | ||
bodyEncoder := query.NewEncoder(bodyWriter) | ||
|
||
if err := presignSerializeOpDocumentSynthesizeSpeechInput(input, bodyEncoder.Value); err != nil { | ||
return out, metadata, &smithy.SerializationError{Err: err} | ||
} | ||
|
||
err = bodyEncoder.Encode() | ||
if err != nil { | ||
return out, metadata, &smithy.SerializationError{Err: err} | ||
} | ||
|
||
if request, err = request.SetStream(bytes.NewReader(bodyWriter.Bytes())); err != nil { | ||
return out, metadata, &smithy.SerializationError{Err: err} | ||
} | ||
|
||
in.Request = request | ||
|
||
return next.HandleSerialize(ctx, in) | ||
} | ||
|
||
func presignSerializeOpDocumentSynthesizeSpeechInput(v *SynthesizeSpeechInput, value query.Value) error { | ||
object := value.Object() | ||
_ = object | ||
|
||
if v.LexiconNames != nil && len(v.LexiconNames) > 0 { | ||
objectKey := object.KeyWithValues("LexiconNames") | ||
for _, name := range v.LexiconNames { | ||
objectKey.String(name) | ||
} | ||
} | ||
|
||
if len(v.OutputFormat) > 0 { | ||
objectKey := object.Key("OutputFormat") | ||
objectKey.String(string(v.OutputFormat)) | ||
} | ||
|
||
if v.SampleRate != nil { | ||
objectKey := object.Key("SampleRate") | ||
objectKey.String(*v.SampleRate) | ||
} | ||
|
||
if v.Text != nil { | ||
objectKey := object.Key("Text") | ||
objectKey.String(*v.Text) | ||
} | ||
|
||
if len(v.TextType) > 0 { | ||
objectKey := object.Key("TextType") | ||
objectKey.String(string(v.TextType)) | ||
} | ||
|
||
if len(v.VoiceId) > 0 { | ||
objectKey := object.Key("VoiceId") | ||
objectKey.String(string(v.VoiceId)) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.