Skip to content

put_lexicon async

put_lexicon(
    name: LexiconName,
    content: LexiconContent,
    *,
    config_overrides: Optional[AsyncPollyClientConfig] = None,
) -> PutLexiconOutput

Stores a pronunciation lexicon in an Amazon Web Services Region. If a lexicon with the same name already exists in the region, it is overwritten by the new lexicon. Lexicon operations have eventual consistency, therefore, it might take some time before the lexicon is available to the SynthesizeSpeech operation.

For more information, see Managing Lexicons.

Parameters:

  • name (LexiconName) –

    Name of the lexicon. The name must follow the regular express format [0-9A-Za-z]{1,20}. That is, the name is a case-sensitive alphanumeric string up to 20 characters long.

  • content (LexiconContent) –

    Content of the PLS lexicon as string data.

Raises:

Examples:

To save a lexicon Stores a pronunciation lexicon in an AWS Region.

>>> await client.put_lexicon(name='W3C', content='<Lexicon Content>')
Source code in docs_src/capo_polly/_services/async_polly.py
async def put_lexicon(
    self,
    name: "capo_polly.types.lexicon_name.LexiconName",
    content: "capo_polly.types.lexicon_content.LexiconContent",
    *,
    config_overrides: Optional[AsyncPollyClientConfig] = None,
) -> "capo_polly.types.put_lexicon_output.PutLexiconOutput":
    """<p>Stores a pronunciation lexicon in an Amazon Web Services Region. If a lexicon with the same name already exists in the region, it is overwritten by the new lexicon. Lexicon operations have eventual consistency, therefore, it might take some time before the lexicon is available to the SynthesizeSpeech operation.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/polly/latest/dg/managing-lexicons.html">Managing Lexicons</a>.</p>

    Args:
        name: <p>Name of the lexicon. The name must follow the regular express format [0-9A-Za-z]{1,20}. That is, the name is a case-sensitive alphanumeric string up to 20 characters long. </p>
        content: <p>Content of the PLS lexicon as string data.</p>

    Raises:
        capo_polly.errors.invalid_lexicon_exception.InvalidLexiconException: <p>Amazon Polly can't find the specified lexicon. Verify that the lexicon's name is spelled correctly, and then try again.</p>
        capo_polly.errors.lexicon_size_exceeded_exception.LexiconSizeExceededException: <p>The maximum size of the specified lexicon would be exceeded by this operation.</p>
        capo_polly.errors.max_lexeme_length_exceeded_exception.MaxLexemeLengthExceededException: <p>The maximum size of the lexeme would be exceeded by this operation.</p>
        capo_polly.errors.max_lexicons_number_exceeded_exception.MaxLexiconsNumberExceededException: <p>The maximum number of lexicons would be exceeded by this operation.</p>
        capo_polly.errors.service_failure_exception.ServiceFailureException: <p>An unknown condition has caused a service failure.</p>
        capo_polly.errors.unsupported_pls_alphabet_exception.UnsupportedPlsAlphabetException: <p>The alphabet specified by the lexicon is not a supported alphabet. Valid values are <code>x-sampa</code> and <code>ipa</code>.</p>
        capo_polly.errors.unsupported_pls_language_exception.UnsupportedPlsLanguageException: <p>The language specified in the lexicon is unsupported. For a list of supported languages, see <a href="https://docs.aws.amazon.com/polly/latest/dg/API_LexiconAttributes.html">Lexicon Attributes</a>.</p>
        capo_polly.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To save a lexicon
        Stores a pronunciation lexicon in an AWS Region.

        >>> await client.put_lexicon(name='W3C', content='<Lexicon Content>')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_polly.types.put_lexicon_input.PutLexiconInput]",
    ) -> AsyncOperationResponse[
        "capo_polly.types.put_lexicon_output.PutLexiconOutput"
    ]:
        import capo_polly._operations.parrot_v1.put_lexicon

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

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

        return capo_polly.types.put_lexicon_input.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutLexicon", redact_input=_redact_input)
    )
    input_: capo_polly.types.put_lexicon_input.PutLexiconInput = {
        "name": name,
        "content": content,
    }

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