Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzo CreateVocabulary
con un AWS SDK o una CLI
Gli esempi di codice seguenti mostrano come utilizzare CreateVocabulary
.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- .NET
-
- AWS SDK for .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
-
Creazione di un vocabolario personalizzato
L'esempio create-vocabulary
seguente crea un vocabolario personalizzato. Per creare un vocabolario personalizzato, devi aver creato un file di testo con tutti i termini che desideri trascrivere in modo più accurato. Per vocabulary-file-uri, specifica l'URI Amazon Simple Storage Service (Amazon S3) di quel file di testo. Per language-code, specifica un codice di lingua corrispondente alla lingua del vocabolario personalizzato. Per vocabulary-name, specifica come vuoi denominare il vocabolario personalizzato.
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
Output:
{
"VocabularyName": "cli-vocab-example",
"LanguageCode": "language-code",
"VocabularyState": "PENDING"
}
Per ulteriori informazioni, consulta Vocabolari personalizzati nella Guida per gli sviluppatori di Amazon Transcribe.
- Python
-
- SDK per 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
Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consulta. Utilizzo di questo servizio con un SDK AWS Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell'SDK.