文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
CreateVocabulary
搭配 a AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 CreateVocabulary
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- .NET
-
- AWS SDK for .NET
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /// <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; }
-
如需 API 詳細資訊,請參閱 CreateVocabulary AWS SDK for .NET 參考中的 API。
-
- CLI
-
- AWS CLI
-
建立自訂詞彙
以下
create-vocabulary
範例會建立自訂詞彙。若要建立自訂詞彙,您必須先建立一個文字檔案,其中包含要更準確轉錄的所有字詞。For vocabulary-file-uri,指定該文字檔案的 Amazon Simple Storage Service (Amazon S3) URI。針對 language-code,指定對應您的自訂詞彙語言的語言代碼。針對 vocabulary-name,指定您自訂詞彙的稱呼。aws transcribe create-vocabulary \ --
language-code
language-code \ --vocabulary-namecli-vocab-example
\ --vocabulary-file-uris3://DOC-EXAMPLE-BUCKET/Amazon-S3-prefix/the-text-file-for-the-custom-vocabulary.txt
輸出:
{ "VocabularyName": "cli-vocab-example", "LanguageCode": "language-code", "VocabularyState": "PENDING" }
如需詳細資訊,請參閱《Amazon Transcribe 開發人員指南》中的自訂詞彙。
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateVocabulary
。
-
- Python
-
- SDK for Python (Boto3)
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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
-
如需 API 詳細資訊,請參閱 CreateVocabulary AWS SDK for Python (Boto3) Word 參考中的 API。
-
動作
DeleteMedicalTranscriptionJob