1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package polly 4 5import ( 6 "context" 7 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 8 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/polly/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12 "io" 13) 14 15// Synthesizes UTF-8 input, plain text or SSML, to a stream of bytes. SSML input 16// must be valid, well-formed SSML. Some alphabets might not be available with all 17// the voices (for example, Cyrillic might not be read at all by English voices) 18// unless phoneme mapping is used. For more information, see How it Works 19// (https://docs.aws.amazon.com/polly/latest/dg/how-text-to-speech-works.html). 20func (c *Client) SynthesizeSpeech(ctx context.Context, params *SynthesizeSpeechInput, optFns ...func(*Options)) (*SynthesizeSpeechOutput, error) { 21 if params == nil { 22 params = &SynthesizeSpeechInput{} 23 } 24 25 result, metadata, err := c.invokeOperation(ctx, "SynthesizeSpeech", params, optFns, addOperationSynthesizeSpeechMiddlewares) 26 if err != nil { 27 return nil, err 28 } 29 30 out := result.(*SynthesizeSpeechOutput) 31 out.ResultMetadata = metadata 32 return out, nil 33} 34 35type SynthesizeSpeechInput struct { 36 37 // The format in which the returned output will be encoded. For audio stream, this 38 // will be mp3, ogg_vorbis, or pcm. For speech marks, this will be json. When pcm 39 // is used, the content returned is audio/pcm in a signed 16-bit, 1 channel (mono), 40 // little-endian format. 41 // 42 // This member is required. 43 OutputFormat types.OutputFormat 44 45 // Input text to synthesize. If you specify ssml as the TextType, follow the SSML 46 // format for the input text. 47 // 48 // This member is required. 49 Text *string 50 51 // Voice ID to use for the synthesis. You can get a list of available voice IDs by 52 // calling the DescribeVoices 53 // (https://docs.aws.amazon.com/polly/latest/dg/API_DescribeVoices.html) operation. 54 // 55 // This member is required. 56 VoiceId types.VoiceId 57 58 // Specifies the engine (standard or neural) for Amazon Polly to use when 59 // processing input text for speech synthesis. For information on Amazon Polly 60 // voices and which voices are available in standard-only, NTTS-only, and both 61 // standard and NTTS formats, see Available Voices 62 // (https://docs.aws.amazon.com/polly/latest/dg/voicelist.html). NTTS-only voices 63 // When using NTTS-only voices such as Kevin (en-US), this parameter is required 64 // and must be set to neural. If the engine is not specified, or is set to 65 // standard, this will result in an error. Type: String Valid Values: standard | 66 // neural Required: Yes Standard voices For standard voices, this is not required; 67 // the engine parameter defaults to standard. If the engine is not specified, or is 68 // set to standard and an NTTS-only voice is selected, this will result in an 69 // error. 70 Engine types.Engine 71 72 // Optional language code for the Synthesize Speech request. This is only necessary 73 // if using a bilingual voice, such as Aditi, which can be used for either Indian 74 // English (en-IN) or Hindi (hi-IN). If a bilingual voice is used and no language 75 // code is specified, Amazon Polly will use the default language of the bilingual 76 // voice. The default language for any voice is the one returned by the 77 // DescribeVoices 78 // (https://docs.aws.amazon.com/polly/latest/dg/API_DescribeVoices.html) operation 79 // for the LanguageCode parameter. For example, if no language code is specified, 80 // Aditi will use Indian English rather than Hindi. 81 LanguageCode types.LanguageCode 82 83 // List of one or more pronunciation lexicon names you want the service to apply 84 // during synthesis. Lexicons are applied only if the language of the lexicon is 85 // the same as the language of the voice. For information about storing lexicons, 86 // see PutLexicon 87 // (https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html). 88 LexiconNames []string 89 90 // The audio frequency specified in Hz. The valid values for mp3 and ogg_vorbis are 91 // "8000", "16000", "22050", and "24000". The default value for standard voices is 92 // "22050". The default value for neural voices is "24000". Valid values for pcm 93 // are "8000" and "16000" The default value is "16000". 94 SampleRate *string 95 96 // The type of speech marks returned for the input text. 97 SpeechMarkTypes []types.SpeechMarkType 98 99 // Specifies whether the input text is plain text or SSML. The default value is 100 // plain text. For more information, see Using SSML 101 // (https://docs.aws.amazon.com/polly/latest/dg/ssml.html). 102 TextType types.TextType 103} 104 105type SynthesizeSpeechOutput struct { 106 107 // Stream containing the synthesized speech. 108 AudioStream io.ReadCloser 109 110 // Specifies the type audio stream. This should reflect the OutputFormat parameter 111 // in your request. 112 // 113 // * If you request mp3 as the OutputFormat, the ContentType 114 // returned is audio/mpeg. 115 // 116 // * If you request ogg_vorbis as the OutputFormat, the 117 // ContentType returned is audio/ogg. 118 // 119 // * If you request pcm as the OutputFormat, 120 // the ContentType returned is audio/pcm in a signed 16-bit, 1 channel (mono), 121 // little-endian format. 122 // 123 // * If you request json as the OutputFormat, the 124 // ContentType returned is audio/json. 125 ContentType *string 126 127 // Number of characters synthesized. 128 RequestCharacters int32 129 130 // Metadata pertaining to the operation's result. 131 ResultMetadata middleware.Metadata 132} 133 134func addOperationSynthesizeSpeechMiddlewares(stack *middleware.Stack, options Options) (err error) { 135 err = stack.Serialize.Add(&awsRestjson1_serializeOpSynthesizeSpeech{}, middleware.After) 136 if err != nil { 137 return err 138 } 139 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSynthesizeSpeech{}, middleware.After) 140 if err != nil { 141 return err 142 } 143 if err = addSetLoggerMiddleware(stack, options); err != nil { 144 return err 145 } 146 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 147 return err 148 } 149 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 150 return err 151 } 152 if err = addResolveEndpointMiddleware(stack, options); err != nil { 153 return err 154 } 155 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 156 return err 157 } 158 if err = addRetryMiddlewares(stack, options); err != nil { 159 return err 160 } 161 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 162 return err 163 } 164 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 165 return err 166 } 167 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 168 return err 169 } 170 if err = addClientUserAgent(stack); err != nil { 171 return err 172 } 173 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 174 return err 175 } 176 if err = addOpSynthesizeSpeechValidationMiddleware(stack); err != nil { 177 return err 178 } 179 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSynthesizeSpeech(options.Region), middleware.Before); err != nil { 180 return err 181 } 182 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 183 return err 184 } 185 if err = addResponseErrorMiddleware(stack); err != nil { 186 return err 187 } 188 if err = addRequestResponseLogging(stack, options); err != nil { 189 return err 190 } 191 return nil 192} 193 194func newServiceMetadataMiddleware_opSynthesizeSpeech(region string) *awsmiddleware.RegisterServiceMetadata { 195 return &awsmiddleware.RegisterServiceMetadata{ 196 Region: region, 197 ServiceID: ServiceID, 198 SigningName: "polly", 199 OperationName: "SynthesizeSpeech", 200 } 201} 202