À utiliser UpdateVocabulary avec un AWS SDKou CLI - Amazon Transcribe

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

À utiliser UpdateVocabulary avec un AWS SDKou CLI

Les exemples de code suivants montrent comment utiliserUpdateVocabulary.

Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant :

.NET
AWS SDK for .NET
Note

Il y en a plus à ce sujet GitHub. Consultez l'exemple complet et apprenez à configurer et à exécuter dans le AWS Référentiel d'exemples de code.

/// <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; }
  • Pour API plus de détails, voir UpdateVocabularydans AWS SDK for .NET APIRéférence.

CLI
AWS CLI

Pour mettre à jour un vocabulaire personnalisé avec de nouveaux termes.

L’exemple update-vocabulary suivant remplace les termes utilisés pour créer un vocabulaire personnalisé par les nouveaux termes que vous fournissez. Prérequis : pour remplacer les termes d’un vocabulaire personnalisé, vous avez besoin d’un fichier contenant les nouveaux termes.

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

Sortie :

{ "VocabularyName": "custom-vocabulary", "LanguageCode": "language", "VocabularyState": "PENDING" }

Pour plus d’informations, consultez Vocabulaires personnalisés dans le Guide du développeur Amazon Transcribe.

  • Pour API plus de détails, voir UpdateVocabularydans AWS CLI Référence de commande.

Python
SDKpour Python (Boto3)
Note

Il y en a plus à ce sujet GitHub. Consultez l'exemple complet et apprenez à configurer et à exécuter dans le AWS Référentiel d'exemples de code.

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
  • Pour API plus de détails, voir UpdateVocabularydans AWS SDKpour Python (Boto3) Reference. API

Pour une liste complète des AWS SDKguides du développeur et exemples de code, voirUtilisation de ce service avec un AWS SDK. Cette rubrique inclut également des informations sur la mise en route et des détails sur SDK les versions précédentes.