Skip to content

create_voice async

create_voice(
    name: CustomVoiceName,
    language_code: CustomVoiceLanguageCode,
    terms_accepted: TermsAccepted,
    voice_creation_data: VoiceCreationData,
    *,
    config_overrides: Optional[AsyncPollyClientConfig] = None,
    customer_managed_encryption: Optional[CustomerManagedEncryption] = None,
    tags: Optional[TagMap] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateVoiceOutput

Creates a custom voice from recordings of a speaker and returns it in pending status. Use GetVoice to check the status. When the status is active, you can use the voice ID in SynthesizeSpeech, StartSpeechSynthesisTask, and StartSpeechSynthesisStream.

The custom-voice-max-count service quota limits the number of custom voices in your account in each Region. If you reach the quota, the request fails with ServiceQuotaExceededException.

This operation requires permissions to perform the polly:CreateVoice action. You also need s3:GetObject permission on each recording that you specify by S3Url. If you specify a customer managed key, you also need kms:DescribeKey, kms:GenerateDataKey, and kms:Decrypt permissions on the key. If you specify Tags, you also need the polly:TagResource permission.

Parameters:

  • name (CustomVoiceName) –

    The name of the voice. Use the name to identify the voice in your application. The name can contain letters, digits, hyphens, and underscores, and can be up to 64 characters long. The name doesn't have to be unique. The name isn't the voice ID, which Amazon Polly assigns.

  • language_code (CustomVoiceLanguageCode) –

    The language of the recordings, for example, en-US. Amazon Polly doesn't detect the language from the recordings.

  • terms_accepted (TermsAccepted) –

    Confirms the following two statements:

    • "I confirm that I have obtained all necessary consents required under any applicable laws and regulations, including biometric privacy laws, from the owner of this voice to clone these voice samples."

    • "I confirm that I will not use the generated content for any illegal, fraudulent, or harmful purpose and reaffirm my obligation to abide by the AWS Service Terms, Biometric Notice and Consent Terms, AWS Responsible AI Policy, and AWS Acceptable Use Policy."

    You can read the AWS Service Terms, the Biometric Notice and Consent Terms, the AWS Responsible AI Policy, and the AWS Acceptable Use Policy on the Amazon Web Services website.

    You must set this parameter to true to create a voice. Otherwise, the request fails with ValidationException.

  • voice_creation_data (VoiceCreationData) –

    The recordings that Amazon Polly uses to create the voice.

  • customer_managed_encryption (Optional[CustomerManagedEncryption], default: None ) –

    The customer managed key that you want Amazon Polly to encrypt the voice with. If you omit this parameter, Amazon Polly encrypts the voice with an Amazon Web Services owned key.

  • tags (Optional[TagMap], default: None ) –

    The tags that you apply to the voice to help you categorize and organize it. Each tag consists of a key and an optional value, both of which you define.

  • client_token (Optional[ClientToken], default: None ) –

    A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If you don't specify a client token, the Amazon Web Services SDKs generate one for you. If you retry a request that succeeded with the same client token and the same parameters, Amazon Polly returns the voice that the first request created and doesn't create a second voice.

Raises:

  • AccessDeniedException –

    You don't have sufficient permissions to perform this action. For a custom voice that uses a customer managed key, Amazon Polly also returns this exception if you don't have the required Amazon Web Services KMS permissions on the key.

  • InvalidTagParameterException –

    The resource ARN or a tag in the request isn't valid. Specify the ARN of a supported resource in the Amazon Web Services account and Region of the request. Tag keys can have a maximum length of 128 characters, and tag values can have a maximum length of 256 characters. Correct the ARN or the tags, and then try again.

  • ServiceFailureException –

    An unknown condition has caused a service failure.

  • ServiceQuotaExceededException –

    The request would cause a service quota to be exceeded.

  • ThrottlingException –

    The request was denied because of request throttling.

  • TooManyTagsException –

    The list of tags on the resource is over the limit. The maximum number of tags that can be applied to a resource is 50. Remove unused tags or reduce the number of tags in the request, and then try again.

  • ValidationException –

    The input fails to satisfy the constraints specified by the service.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_polly/_services/async_polly.py
async def create_voice(
    self,
    name: "capo_polly.types.custom_voice_name.CustomVoiceName",
    language_code: "capo_polly.types.custom_voice_language_code.CustomVoiceLanguageCode",
    terms_accepted: "capo_polly.types.terms_accepted.TermsAccepted",
    voice_creation_data: "capo_polly.types.voice_creation_data.VoiceCreationData",
    *,
    config_overrides: Optional[AsyncPollyClientConfig] = None,
    customer_managed_encryption: Optional[
        "capo_polly.types.customer_managed_encryption.CustomerManagedEncryption"
    ] = None,
    tags: Optional["capo_polly.types.tag_map.TagMap"] = None,
    client_token: Optional["capo_polly.types.client_token.ClientToken"] = None,
) -> "capo_polly.types.create_voice_output.CreateVoiceOutput":
    """<p>Creates a custom voice from recordings of a speaker and returns it in <code>pending</code> status. Use <code>GetVoice</code> to check the status. When the status is <code>active</code>, you can use the voice ID in <code>SynthesizeSpeech</code>, <code>StartSpeechSynthesisTask</code>, and <code>StartSpeechSynthesisStream</code>.</p> <p>The <code>custom-voice-max-count</code> service quota limits the number of custom voices in your account in each Region. If you reach the quota, the request fails with <code>ServiceQuotaExceededException</code>.</p> <p>This operation requires permissions to perform the <code>polly:CreateVoice</code> action. You also need <code>s3:GetObject</code> permission on each recording that you specify by <code>S3Url</code>. If you specify a customer managed key, you also need <code>kms:DescribeKey</code>, <code>kms:GenerateDataKey</code>, and <code>kms:Decrypt</code> permissions on the key. If you specify <code>Tags</code>, you also need the <code>polly:TagResource</code> permission.</p>

    Args:
        name: <p>The name of the voice. Use the name to identify the voice in your application. The name can contain letters, digits, hyphens, and underscores, and can be up to 64 characters long. The name doesn't have to be unique. The name isn't the voice ID, which Amazon Polly assigns.</p>
        language_code: <p>The language of the recordings, for example, <code>en-US</code>. Amazon Polly doesn't detect the language from the recordings.</p>
        terms_accepted: <p>Confirms the following two statements:</p> <ul> <li> <p>"I confirm that I have obtained all necessary consents required under any applicable laws and regulations, including biometric privacy laws, from the owner of this voice to clone these voice samples."</p> </li> <li> <p>"I confirm that I will not use the generated content for any illegal, fraudulent, or harmful purpose and reaffirm my obligation to abide by the AWS Service Terms, Biometric Notice and Consent Terms, AWS Responsible AI Policy, and AWS Acceptable Use Policy."</p> </li> </ul> <p>You can read the <a href="https://aws.amazon.com/service-terms/">AWS Service Terms</a>, the <a href="https://aws.amazon.com/legal/biometric-notice-and-consent-terms/">Biometric Notice and Consent Terms</a>, the <a href="https://aws.amazon.com/ai/responsible-ai/policy/">AWS Responsible AI Policy</a>, and the <a href="https://aws.amazon.com/aup/">AWS Acceptable Use Policy</a> on the Amazon Web Services website.</p> <p>You must set this parameter to <code>true</code> to create a voice. Otherwise, the request fails with <code>ValidationException</code>.</p>
        voice_creation_data: <p>The recordings that Amazon Polly uses to create the voice.</p>
        customer_managed_encryption: <p>The customer managed key that you want Amazon Polly to encrypt the voice with. If you omit this parameter, Amazon Polly encrypts the voice with an Amazon Web Services owned key.</p>
        tags: <p>The tags that you apply to the voice to help you categorize and organize it. Each tag consists of a key and an optional value, both of which you define.</p>
        client_token: <p>A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If you don't specify a client token, the Amazon Web Services SDKs generate one for you. If you retry a request that succeeded with the same client token and the same parameters, Amazon Polly returns the voice that the first request created and doesn't create a second voice.</p>

    Raises:
        capo_polly.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient permissions to perform this action. For a custom voice that uses a customer managed key, Amazon Polly also returns this exception if you don't have the required Amazon Web Services KMS permissions on the key.</p>
        capo_polly.errors.invalid_tag_parameter_exception.InvalidTagParameterException: <p>The resource ARN or a tag in the request isn't valid. Specify the ARN of a supported resource in the Amazon Web Services account and Region of the request. Tag keys can have a maximum length of 128 characters, and tag values can have a maximum length of 256 characters. Correct the ARN or the tags, and then try again.</p>
        capo_polly.errors.service_failure_exception.ServiceFailureException: <p>An unknown condition has caused a service failure.</p>
        capo_polly.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would cause a service quota to be exceeded.</p>
        capo_polly.errors.throttling_exception.ThrottlingException: <p>The request was denied because of request throttling.</p>
        capo_polly.errors.too_many_tags_exception.TooManyTagsException: <p>The list of tags on the resource is over the limit. The maximum number of tags that can be applied to a resource is 50. Remove unused tags or reduce the number of tags in the request, and then try again.</p>
        capo_polly.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints specified by the service.</p>
        capo_polly.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_polly.types.create_voice_input.CreateVoiceInput]",
    ) -> AsyncOperationResponse[
        "capo_polly.types.create_voice_output.CreateVoiceOutput"
    ]:
        import capo_polly._operations.parrot_v1.create_voice

        (
            output,
            http_response,
        ) = await capo_polly._operations.parrot_v1.create_voice.async_create_voice(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_polly.types.create_voice_input.CreateVoiceInput",
    ) -> dict[str, Any]:
        import capo_polly.types.create_voice_input

        return capo_polly.types.create_voice_input.redact_sensitive(input_)

    def _redact_output(
        output: "capo_polly.types.create_voice_output.CreateVoiceOutput",
    ) -> dict[str, Any]:
        import capo_polly.types.create_voice_output

        return capo_polly.types.create_voice_output.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateVoice", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_polly.types.create_voice_input.CreateVoiceInput = {
        "name": name,
        "language_code": language_code,
        "terms_accepted": terms_accepted,
        "voice_creation_data": voice_creation_data,
    }
    if customer_managed_encryption is not None:
        input_["customer_managed_encryption"] = customer_managed_encryption
    if tags is not None:
        input_["tags"] = tags
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output