1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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
}
|