Skip to content

create_vocabulary

create_vocabulary(
    vocabulary_name: VocabularyName,
    language_code: LanguageCode,
    *,
    config_overrides: Optional[TranscribeClientConfig] = None,
    phrases: Optional[Phrases] = None,
    vocabulary_file_uri: Optional[Uri] = None,
    tags: Optional[TagList] = None,
    data_access_role_arn: Optional[DataAccessRoleArn] = None,
    encryption_configuration: Optional[EncryptionConfiguration] = None,
) -> CreateVocabularyResponse

Creates a new custom vocabulary.

When creating a new custom vocabulary, you can either upload a text file that contains your new entries, phrases, and terms into an Amazon S3 bucket and include the URI in your request. Or you can include a list of terms directly in your request using the Phrases flag.

Each language has a character set that contains all allowed characters for that specific language. If you use unsupported characters, your custom vocabulary request fails. Refer to Character Sets for Custom Vocabularies to get the character set for your language.

For more information, see Custom vocabularies.

Parameters:

  • vocabulary_name (VocabularyName) –

    A unique name, chosen by you, for your new custom vocabulary.

    This name is case sensitive, cannot contain spaces, and must be unique within an Amazon Web Services account. If you try to create a new custom vocabulary with the same name as an existing custom vocabulary, you get a ConflictException error.

  • language_code (LanguageCode) –

    The language code that represents the language of the entries in your custom vocabulary. Each custom vocabulary must contain terms in only one language.

    A custom vocabulary can only be used to transcribe files in the same language as the custom vocabulary. For example, if you create a custom vocabulary using US English (en-US), you can only apply this custom vocabulary to files that contain English audio.

    For a list of supported languages and their associated language codes, refer to the Supported languages table.

  • phrases (Optional[Phrases], default: None ) –

    Use this parameter if you want to create your custom vocabulary by including all desired terms, as comma-separated values, within your request. The other option for creating your custom vocabulary is to save your entries in a text file and upload them to an Amazon S3 bucket, then specify the location of your file using the VocabularyFileUri parameter.

    Note that if you include Phrases in your request, you cannot use VocabularyFileUri; you must choose one or the other.

    Each language has a character set that contains all allowed characters for that specific language. If you use unsupported characters, your custom vocabulary filter request fails. Refer to Character Sets for Custom Vocabularies to get the character set for your language.

  • vocabulary_file_uri (Optional[Uri], default: None ) –

    The Amazon S3 location of the text file that contains your custom vocabulary. The URI must be located in the same Amazon Web Services Region as the resource you're calling.

    Here's an example URI path: s3://DOC-EXAMPLE-BUCKET/my-vocab-file.txt

    Note that if you include VocabularyFileUri in your request, you cannot use the Phrases flag; you must choose one or the other.

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

    Adds one or more custom tags, each in the form of a key:value pair, to a new custom vocabulary at the time you create this new custom vocabulary.

    To learn more about using tags with Amazon Transcribe, refer to Tagging resources.

  • data_access_role_arn (Optional[DataAccessRoleArn], default: None ) –

    The Amazon Resource Name (ARN) of an IAM role that has permissions to access the Amazon S3 bucket that contains your input files (in this case, your custom vocabulary). If you include EncryptionConfiguration in your request, this role must also have permissions to access the specified KMS key. If the role that you specify doesn’t have the appropriate permissions, your request fails.

    IAM role ARNs have the format arn:partition:iam::account:role/role-name-with-path. For example: arn:aws:iam::111122223333:role/Admin.

    For more information, see IAM ARNs.

  • encryption_configuration (Optional[EncryptionConfiguration], default: None ) –

    Specifies the encryption configuration for your custom vocabulary. Your vocabulary artifacts are encrypted with the specified KMS key or with an AWS-owned key if a key is not supplied.

Raises:

  • BadRequestException –

    Your request didn't pass one or more validation tests. This can occur when the entity you're trying to delete doesn't exist or if it's in a non-terminal state (such as IN PROGRESS). See the exception message field for more information.

  • ConflictException –

    A resource already exists with this name. Resource names must be unique within an Amazon Web Services account.

  • InternalFailureException –

    There was an internal error. Check the error message, correct the issue, and try your request again.

  • LimitExceededException –

    You've either sent too many requests or your input file is too long. Wait before retrying your request, or use a smaller file and try your request again.

  • UnknownServiceError –

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

Source code in docs_src/capo_transcribe/_services/transcribe.py
def create_vocabulary(
    self,
    vocabulary_name: "capo_transcribe.types.vocabulary_name.VocabularyName",
    language_code: "capo_transcribe.types.language_code.LanguageCode",
    *,
    config_overrides: Optional[TranscribeClientConfig] = None,
    phrases: Optional["capo_transcribe.types.phrases.Phrases"] = None,
    vocabulary_file_uri: Optional["capo_transcribe.types.uri.Uri"] = None,
    tags: Optional["capo_transcribe.types.tag_list.TagList"] = None,
    data_access_role_arn: Optional[
        "capo_transcribe.types.data_access_role_arn.DataAccessRoleArn"
    ] = None,
    encryption_configuration: Optional[
        "capo_transcribe.types.encryption_configuration.EncryptionConfiguration"
    ] = None,
) -> "capo_transcribe.types.create_vocabulary_response.CreateVocabularyResponse":
    """<p>Creates a new custom vocabulary.</p> <p>When creating a new custom vocabulary, you can either upload a text file that contains your new entries, phrases, and terms into an Amazon S3 bucket and include the URI in your request. Or you can include a list of terms directly in your request using the <code>Phrases</code> flag.</p> <p>Each language has a character set that contains all allowed characters for that specific language. If you use unsupported characters, your custom vocabulary request fails. Refer to <a href="https://docs.aws.amazon.com/transcribe/latest/dg/charsets.html">Character Sets for Custom Vocabularies</a> to get the character set for your language.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/transcribe/latest/dg/custom-vocabulary.html">Custom vocabularies</a>.</p>

    Args:
        vocabulary_name: <p>A unique name, chosen by you, for your new custom vocabulary.</p> <p>This name is case sensitive, cannot contain spaces, and must be unique within an Amazon Web Services account. If you try to create a new custom vocabulary with the same name as an existing custom vocabulary, you get a <code>ConflictException</code> error.</p>
        language_code: <p>The language code that represents the language of the entries in your custom vocabulary. Each custom vocabulary must contain terms in only one language.</p> <p>A custom vocabulary can only be used to transcribe files in the same language as the custom vocabulary. For example, if you create a custom vocabulary using US English (<code>en-US</code>), you can only apply this custom vocabulary to files that contain English audio.</p> <p>For a list of supported languages and their associated language codes, refer to the <a href="https://docs.aws.amazon.com/transcribe/latest/dg/supported-languages.html">Supported languages</a> table.</p>
        phrases: <p>Use this parameter if you want to create your custom vocabulary by including all desired terms, as comma-separated values, within your request. The other option for creating your custom vocabulary is to save your entries in a text file and upload them to an Amazon S3 bucket, then specify the location of your file using the <code>VocabularyFileUri</code> parameter.</p> <p>Note that if you include <code>Phrases</code> in your request, you cannot use <code>VocabularyFileUri</code>; you must choose one or the other.</p> <p>Each language has a character set that contains all allowed characters for that specific language. If you use unsupported characters, your custom vocabulary filter request fails. Refer to <a href="https://docs.aws.amazon.com/transcribe/latest/dg/charsets.html">Character Sets for Custom Vocabularies</a> to get the character set for your language.</p>
        vocabulary_file_uri: <p>The Amazon S3 location of the text file that contains your custom vocabulary. The URI must be located in the same Amazon Web Services Region as the resource you're calling.</p> <p>Here's an example URI path: <code>s3://DOC-EXAMPLE-BUCKET/my-vocab-file.txt</code> </p> <p>Note that if you include <code>VocabularyFileUri</code> in your request, you cannot use the <code>Phrases</code> flag; you must choose one or the other.</p>
        tags: <p>Adds one or more custom tags, each in the form of a key:value pair, to a new custom vocabulary at the time you create this new custom vocabulary.</p> <p>To learn more about using tags with Amazon Transcribe, refer to <a href="https://docs.aws.amazon.com/transcribe/latest/dg/tagging.html">Tagging resources</a>.</p>
        data_access_role_arn: <p>The Amazon Resource Name (ARN) of an IAM role that has permissions to access the Amazon S3 bucket that contains your input files (in this case, your custom vocabulary). If you include <code>EncryptionConfiguration</code> in your request, this role must also have permissions to access the specified KMS key. If the role that you specify doesn’t have the appropriate permissions, your request fails.</p> <p>IAM role ARNs have the format <code>arn:partition:iam::account:role/role-name-with-path</code>. For example: <code>arn:aws:iam::111122223333:role/Admin</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns">IAM ARNs</a>.</p>
        encryption_configuration: <p>Specifies the encryption configuration for your custom vocabulary. Your vocabulary artifacts are encrypted with the specified KMS key or with an AWS-owned key if a key is not supplied.</p>

    Raises:
        capo_transcribe.errors.bad_request_exception.BadRequestException: <p>Your request didn't pass one or more validation tests. This can occur when the entity you're trying to delete doesn't exist or if it's in a non-terminal state (such as <code>IN PROGRESS</code>). See the exception message field for more information.</p>
        capo_transcribe.errors.conflict_exception.ConflictException: <p>A resource already exists with this name. Resource names must be unique within an Amazon Web Services account.</p>
        capo_transcribe.errors.internal_failure_exception.InternalFailureException: <p>There was an internal error. Check the error message, correct the issue, and try your request again.</p>
        capo_transcribe.errors.limit_exceeded_exception.LimitExceededException: <p>You've either sent too many requests or your input file is too long. Wait before retrying your request, or use a smaller file and try your request again.</p>
        capo_transcribe.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_transcribe.types.create_vocabulary_request.CreateVocabularyRequest]",
    ) -> OperationResponse[
        "capo_transcribe.types.create_vocabulary_response.CreateVocabularyResponse"
    ]:
        import capo_transcribe._operations.transcribe.create_vocabulary

        output, http_response = (
            capo_transcribe._operations.transcribe.create_vocabulary.create_vocabulary(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateVocabulary")
    )
    input_: capo_transcribe.types.create_vocabulary_request.CreateVocabularyRequest = {
        "vocabulary_name": vocabulary_name,
        "language_code": language_code,
    }
    if phrases is not None:
        input_["phrases"] = phrases
    if vocabulary_file_uri is not None:
        input_["vocabulary_file_uri"] = vocabulary_file_uri
    if tags is not None:
        input_["tags"] = tags
    if data_access_role_arn is not None:
        input_["data_access_role_arn"] = data_access_role_arn
    if encryption_configuration is not None:
        input_["encryption_configuration"] = encryption_configuration

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output