

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用清單建立自訂詞彙
<a name="custom-vocabulary-create-list"></a>

**重要**  
清單格式的自訂詞彙已被取代，因此，如果您要建立新的自訂詞彙，我們強烈建議您使用[表格格式](custom-vocabulary-create-table.md)。

您可以使用 AWS 管理主控台 AWS CLI、 或 AWS SDKs 從清單中建立自訂詞彙。
+ **AWS 管理主控台**：您必須建立並上傳包含自訂詞彙的文字檔案。您可以使用以分行符號或逗號分隔的項目。請注意，您的清單必須以 `LF` 格式儲存為文字 (\$1.txt) 檔案。如果您使用任何其他格式，例如 `CRLF`，您的自訂詞彙將無法被 Amazon Transcribe接受。
+ **AWS CLI** 和 **AWS SDK**：您必須使用 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html#transcribe-CreateVocabulary-request-Phrases](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html#transcribe-CreateVocabulary-request-Phrases) 標記，在 API 呼叫中以逗號分隔的項目納入自訂詞彙。

如果項目包含多個單字，您必須使用連字符連接每個單字。例如，您將以 **Los-Angeles** 納入「Los Angeles」和以 **Andorra-la-Vella** 納入「Andorra la Vella」。

以下是兩種有效清單格式的範例。請參閱 [建立自訂詞彙清單](#custom-vocabulary-create-list-examples)，取得方法特定範例。
+ 以逗號分隔的項目：

  ```
  Los-Angeles,CLI,Eva-Maria,ABCs,Andorra-la-Vella
  ```
+ 分行符號的項目：

  ```
  Los-Angeles
  CLI
  Eva-Maria
  ABCs
  Andorra-la-Vella
  ```

**重要**  
您僅可使用您的語言支援的字元。請參閱您語言的[字元集](charsets.md)，了解詳細資訊。

[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateMedicalVocabulary.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateMedicalVocabulary.html) 操作不支援自訂詞彙清單。如果要建立自訂醫療詞彙，您必須使用表格格式；請參閱 [使用資料表建立自訂詞彙](custom-vocabulary-create-table.md)，了解說明指示。

## 建立自訂詞彙清單
<a name="custom-vocabulary-create-list-examples"></a>

若要處理要搭配 使用的自訂詞彙清單 Amazon Transcribe，請參閱下列範例：

### AWS CLI
<a name="vocab-create-list-cli"></a>

此範例使用 [create-vocabulary](https://docs.aws.amazon.com/cli/latest/reference/transcribe/create-vocabulary.html) 指令並搭配清單格式的自訂詞彙檔案。如需詳細資訊，請參閱[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html)。

```
aws transcribe create-vocabulary \ 
--vocabulary-name my-first-vocabulary \ 
--language-code en-US \ 
--phrases {CLI,Eva-Maria,ABCs}
```

這是使用 [create-vocabulary](https://docs.aws.amazon.com/cli/latest/reference/transcribe/create-vocabulary.html) 指令的另一個範例，以及建立自訂詞彙的請求內文。

```
aws transcribe create-vocabulary \
--cli-input-json file://filepath/my-first-vocab-list.json
```

檔案 *my-first-vocab-list.json* 包含以下請求主文。

```
{
  "VocabularyName": "my-first-vocabulary",
  "LanguageCode": "en-US",
  "Phrases": [
        "CLI","Eva-Maria","ABCs"
  ]
}
```

`VocabularyState` 從 `PENDING` 變更為 `READY` 後，您的自訂詞彙即可與轉錄搭配使用。執行下列指令可檢視自訂詞彙的目前狀態：

```
aws transcribe get-vocabulary \
--vocabulary-name my-first-vocabulary
```

### 適用於 Python (Boto3) 的 AWS SDK
<a name="vocab-create-list-python-batch"></a>

此範例使用 從清單使用 [create\$1vocabulary ](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/transcribe.html#TranscribeService.Client.create_vocabulary)方法 適用於 Python (Boto3) 的 AWS SDK 建立自訂詞彙。如需詳細資訊，請參閱[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html)。

如需使用 AWS SDKs 的其他範例，包括功能特定、案例和跨服務範例，請參閱 [Amazon Transcribe AWS SDKs的程式碼範例](service_code_examples.md)章節。

```
from __future__ import print_function
import time
import boto3
transcribe = boto3.client('transcribe', 'us-west-2')
vocab_name = "my-first-vocabulary"
response = transcribe.create_vocabulary(
    LanguageCode = 'en-US',
    VocabularyName = vocab_name,
    Phrases = [
        'CLI','Eva-Maria','ABCs'
    ]
)

while True:
    status = transcribe.get_vocabulary(VocabularyName = vocab_name)
    if status['VocabularyState'] in ['READY', 'FAILED']:
        break
    print("Not ready yet...")
    time.sleep(5)
print(status)
```

**注意**  
如果您為自訂詞彙檔案建立新的儲存 Amazon S3 貯體，請確定提出[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabulary.html)請求 IAM 的角色具有存取此儲存貯體的許可。如果角色沒有正確的授權，您的請求將失敗。您可以選擇性地在請求中指定 IAM 角色，方法是包含 `DataAccessRoleArn` 參數。如需 中 IAM 角色和政策的詳細資訊 Amazon Transcribe，請參閱 [Amazon Transcribe 身分型政策範例](security_iam_id-based-policy-examples.md)。