UpdateVocabulary搭配使用 AWS SDK或 CLI - Amazon Transcribe

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

UpdateVocabulary搭配使用 AWS SDK或 CLI

以下代码示例演示如何使用 UpdateVocabulary

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
AWS SDK for .NET
注意

还有更多相关信息 GitHub。在中查找完整的示例,学习如何设置和运行 AWS 代码示例存储库

/// <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; }
  • 有关API详细信息,请参阅UpdateVocabulary中的 AWS SDK for .NET API参考

CLI
AWS CLI

使用新术语更新自定义词汇表。

以下 update-vocabulary 示例使用您提供的新术语来覆盖用于创建自定义词汇表的术语。先决条件:要替换自定义词汇表中的术语,您需要使用一个包含新术语的文件。

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

输出:

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

有关更多信息,请参阅《Amazon Transcribe 开发人员指南》中的自定义词汇表

  • 有关API详细信息,请参阅UpdateVocabulary中的 AWS CLI 命令参考

Python
SDK适用于 Python (Boto3)
注意

还有更多相关信息 GitHub。在中查找完整的示例,学习如何设置和运行 AWS 代码示例存储库

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
  • 有关API详细信息,请参阅UpdateVocabulary中的 AWS SDK供参考 Python (Boto3) API。

有关完整列表 AWS SDK开发者指南和代码示例,请参阅将此服务与 AWS SDK 配合使用。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。