As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Use CreateVocabulary com um AWS SDK ou CLI
Os exemplos de código a seguir mostram como usar o CreateVocabulary.
Exemplos de ações são trechos de código de programas maiores e devem ser executados em contexto. É possível ver essa ação em contexto no seguinte exemplo de código:
- .NET
-
- SDK para .NET
-
/// <summary>
/// Create a custom vocabulary using a list of phrases. Custom vocabularies
/// improve transcription accuracy for one or more specific words.
/// </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> CreateCustomVocabulary(LanguageCode languageCode,
List<string> phrases, string vocabularyName)
{
var response = await _amazonTranscribeService.CreateVocabularyAsync(
new CreateVocabularyRequest
{
LanguageCode = languageCode,
Phrases = phrases,
VocabularyName = vocabularyName
});
return response.VocabularyState;
}
- CLI
-
- AWS CLI
-
Como criar um vocabulário personalizado
O exemplo de create-vocabulary a seguir cria um vocabulário personalizado. Para criar um vocabulário personalizado, você deve ter criado um arquivo de texto com todos os termos que deseja transcrever com mais precisão. Para vocabulary-file-uri, especifique o URI do Amazon Simple Storage Service (Amazon S3) desse arquivo de texto. Em language-code, especifique um código de idioma correspondente ao idioma do vocabulário personalizado. Em vocabulary-name, especifique como você deseja chamar seu vocabulário personalizado.
aws transcribe create-vocabulary \
--language-code language-code \
--vocabulary-name cli-vocab-example \
--vocabulary-file-uri s3://amzn-s3-demo-bucket/Amazon-S3-prefix/the-text-file-for-the-custom-vocabulary.txt
Saída:
{
"VocabularyName": "cli-vocab-example",
"LanguageCode": "language-code",
"VocabularyState": "PENDING"
}
Para obter mais informações, consulte Custom Vocabularies no Guia do desenvolvedor do Amazon Transcribe.
- Python
-
- SDK para Python (Boto3)
-
def create_vocabulary(
vocabulary_name, language_code, transcribe_client, phrases=None, table_uri=None
):
"""
Creates a custom vocabulary that can be used to improve the accuracy of
transcription jobs. This function returns as soon as the vocabulary processing
is started. Call get_vocabulary to get the current status of the vocabulary.
The vocabulary is ready to use when its status is 'READY'.
:param vocabulary_name: The name of the custom vocabulary.
:param language_code: The language code of the vocabulary.
For example, en-US or nl-NL.
: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.
:return: Information about the newly created 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.create_vocabulary(**vocab_args)
logger.info("Created custom vocabulary %s.", response["VocabularyName"])
except ClientError:
logger.exception("Couldn't create custom vocabulary %s.", vocabulary_name)
raise
else:
return response
Para obter uma lista completa dos guias do desenvolvedor do AWS SDK e exemplos de código, consulteUsando esse serviço com um AWS SDK. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.