Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use UpdateVocabulary
with an Amazon SDK or CLI
The following code examples show how to use UpdateVocabulary
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code example:
- .NET
-
- Amazon SDK for .NET
-
/// <summary>
/// Update a custom vocabulary with new values. Update overwrites all existing information.
/// </summary>
/// <param name="languageCode">The language code of the vocabulary.</param>
/// <param name="phrases">Phrases to use in the vocabulary.</param>
/// <param name="vocabularyName">Name for the vocabulary.</param>
/// <returns>The state of the custom vocabulary.</returns>
public async Task<VocabularyState> UpdateCustomVocabulary(LanguageCode languageCode,
List<string> phrases, string vocabularyName)
{
var response = await _amazonTranscribeService.UpdateVocabularyAsync(
new UpdateVocabularyRequest()
{
LanguageCode = languageCode,
Phrases = phrases,
VocabularyName = vocabularyName
});
return response.VocabularyState;
}
- CLI
-
- Amazon CLI
-
To update a custom vocabulary with new terms.
The following update-vocabulary
example overwrites the terms used to create a custom vocabulary with the new ones that you provide. Prerequisite: to replace the terms in a custom vocabulary, you need a file with new terms.
aws transcribe update-vocabulary \
--vocabulary-file-uri s3://DOC-EXAMPLE-BUCKET/Amazon-S3-Prefix/custom-vocabulary.txt
\
--vocabulary-name custom-vocabulary
\
--language-code
language-code
Output:
{
"VocabularyName": "custom-vocabulary",
"LanguageCode": "language",
"VocabularyState": "PENDING"
}
For more information, see Custom Vocabularies in the Amazon Transcribe Developer Guide.
- Python
-
- SDK for Python (Boto3)
-
def update_vocabulary(
vocabulary_name, language_code, transcribe_client, phrases=None, table_uri=None
):
"""
Updates an existing custom vocabulary. The entire vocabulary is replaced with
the contents of the update.
:param vocabulary_name: The name of the vocabulary to update.
:param language_code: The language code of the vocabulary.
:param transcribe_client: The Boto3 Transcribe client.
:param phrases: A list of comma-separated phrases to include in the vocabulary.
:param table_uri: A table of phrases and pronunciation hints to include in the
vocabulary.
"""
try:
vocab_args = {"VocabularyName": vocabulary_name, "LanguageCode": language_code}
if phrases is not None:
vocab_args["Phrases"] = phrases
elif table_uri is not None:
vocab_args["VocabularyFileUri"] = table_uri
response = transcribe_client.update_vocabulary(**vocab_args)
logger.info("Updated custom vocabulary %s.", response["VocabularyName"])
except ClientError:
logger.exception("Couldn't update custom vocabulary %s.", vocabulary_name)
raise
For a complete list of Amazon SDK developer guides and code examples, see
Using this service with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.