startSpeechSynthesisTask method

Future<StartSpeechSynthesisTaskOutput> startSpeechSynthesisTask({
  1. required OutputFormat outputFormat,
  2. required String outputS3BucketName,
  3. required String text,
  4. required VoiceId voiceId,
  5. Engine? engine,
  6. LanguageCode? languageCode,
  7. List<String>? lexiconNames,
  8. String? outputS3KeyPrefix,
  9. String? sampleRate,
  10. String? snsTopicArn,
  11. List<SpeechMarkType>? speechMarkTypes,
  12. TextType? textType,
})

Allows the creation of an asynchronous synthesis task, by starting a new SpeechSynthesisTask. This operation requires all the standard information needed for speech synthesis, plus the name of an Amazon S3 bucket for the service to store the output of the synthesis task and two optional parameters (OutputS3KeyPrefix and SnsTopicArn). Once the synthesis task is created, this operation will return a SpeechSynthesisTask object, which will include an identifier of this task as well as the current status.

May throw TextLengthExceededException. May throw InvalidS3BucketException. May throw InvalidS3KeyException. May throw InvalidSampleRateException. May throw InvalidSnsTopicArnException. May throw InvalidSsmlException. May throw EngineNotSupportedException. May throw LexiconNotFoundException. May throw ServiceFailureException. May throw MarksNotSupportedForFormatException. May throw SsmlMarksNotSupportedForTextTypeException. May throw LanguageNotSupportedException.

Parameter outputFormat : The format in which the returned output will be encoded. For audio stream, this will be mp3, ogg_vorbis, or pcm. For speech marks, this will be json.

Parameter outputS3BucketName : Amazon S3 bucket name to which the output file will be saved.

Parameter text : The input text to synthesize. If you specify ssml as the TextType, follow the SSML format for the input text.

Parameter voiceId : Voice ID to use for the synthesis.

Parameter engine : Specifies the engine (standard or neural) for Amazon Polly to use when processing input text for speech synthesis. Using a voice that is not supported for the engine selected will result in an error.

Parameter languageCode : Optional language code for the Speech Synthesis request. This is only necessary if using a bilingual voice, such as Aditi, which can be used for either Indian English (en-IN) or Hindi (hi-IN).

If a bilingual voice is used and no language code is specified, Amazon Polly will use the default language of the bilingual voice. The default language for any voice is the one returned by the DescribeVoices operation for the LanguageCode parameter. For example, if no language code is specified, Aditi will use Indian English rather than Hindi.

Parameter lexiconNames : List of one or more pronunciation lexicon names you want the service to apply during synthesis. Lexicons are applied only if the language of the lexicon is the same as the language of the voice.

Parameter outputS3KeyPrefix : The Amazon S3 key prefix for the output speech file.

Parameter sampleRate : The audio frequency specified in Hz.

The valid values for mp3 and ogg_vorbis are "8000", "16000", "22050", and "24000". The default value for standard voices is "22050". The default value for neural voices is "24000".

Valid values for pcm are "8000" and "16000" The default value is "16000".

Parameter snsTopicArn : ARN for the SNS topic optionally used for providing status notification for a speech synthesis task.

Parameter speechMarkTypes : The type of speech marks returned for the input text.

Parameter textType : Specifies whether the input text is plain text or SSML. The default value is plain text.

Implementation

Future<StartSpeechSynthesisTaskOutput> startSpeechSynthesisTask({
  required OutputFormat outputFormat,
  required String outputS3BucketName,
  required String text,
  required VoiceId voiceId,
  Engine? engine,
  LanguageCode? languageCode,
  List<String>? lexiconNames,
  String? outputS3KeyPrefix,
  String? sampleRate,
  String? snsTopicArn,
  List<SpeechMarkType>? speechMarkTypes,
  TextType? textType,
}) async {
  ArgumentError.checkNotNull(outputFormat, 'outputFormat');
  ArgumentError.checkNotNull(outputS3BucketName, 'outputS3BucketName');
  ArgumentError.checkNotNull(text, 'text');
  ArgumentError.checkNotNull(voiceId, 'voiceId');
  final $payload = <String, dynamic>{
    'OutputFormat': outputFormat.toValue(),
    'OutputS3BucketName': outputS3BucketName,
    'Text': text,
    'VoiceId': voiceId.toValue(),
    if (engine != null) 'Engine': engine.toValue(),
    if (languageCode != null) 'LanguageCode': languageCode.toValue(),
    if (lexiconNames != null) 'LexiconNames': lexiconNames,
    if (outputS3KeyPrefix != null) 'OutputS3KeyPrefix': outputS3KeyPrefix,
    if (sampleRate != null) 'SampleRate': sampleRate,
    if (snsTopicArn != null) 'SnsTopicArn': snsTopicArn,
    if (speechMarkTypes != null)
      'SpeechMarkTypes': speechMarkTypes.map((e) => e.toValue()).toList(),
    if (textType != null) 'TextType': textType.toValue(),
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/v1/synthesisTasks',
    exceptionFnMap: _exceptionFns,
  );
  return StartSpeechSynthesisTaskOutput.fromJson(response);
}