

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

# 建立詞彙篩選條件
<a name="vocabulary-filter-create"></a>

有兩個選項可建立自訂詞彙篩選：

1. 使用 UTF-8 編碼將以行分隔的單字清單儲存為純文字檔案。
   + 您可以搭配 AWS 管理主控台 AWS CLI、 或 AWS SDKs使用此方法。
   + 如果使用 AWS 管理主控台，您可以為自訂詞彙檔案提供本機路徑或 Amazon S3 URI。
   + 如果使用 AWS CLI AWS SDKs，您必須將自訂詞彙檔案上傳至 Amazon S3 儲存貯體，並在請求中包含 Amazon S3 URI。

1. 直接在 API 請求中包含逗號分隔單字的清單。
   + 您可以使用 參數搭配 AWS CLI 或 AWS SDKs 使用此方法[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabularyFilter.html#transcribe-CreateVocabularyFilter-request-Words](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabularyFilter.html#transcribe-CreateVocabularyFilter-request-Words)。

如需每種方法的範例，請參閱 [建立自訂詞彙篩選](#vocabulary-filtering-create-examples)

建立自訂詞彙篩選時要注意的事項：
+ 關鍵字不區分大小寫。例如，「curse (詛咒)」和「CURSE (詛咒)」會視為同一個單字。
+ 只會篩選完全相符的字詞。例如，如果您的篩選包含「swear(宣誓)」，但您的媒體包含「swears(發誓)」或「swearing(發誓)」一詞，則不會篩選這些單字。只有「swear(發誓)」的執行個體會被篩選。因此，您必須包含要篩選的單字的所有變體。
+ 篩選不適用於包含在其他單字中的單字。例如，如果詞彙篩選包含「marine(海洋)」，但不包含「submarine(潛艇)」，則「submarine(潛艇)」就會出現在您的轉錄結果中。
+ 每個項目只能包含一個單字 (不可包含空格)。
+ 如果您將自訂詞彙篩選儲存為文字檔案，則必須使用 UTF-8 編碼的純文字格式。
+ 每個 最多可以有 100 個自訂詞彙篩選條件 AWS 帳戶 ，每個最多可以有 50 Kb 的大小。
+ 您僅可使用您的語言支援的字元。請參閱您語言的[字元集](charsets.md)，了解詳細資訊。

## 建立自訂詞彙篩選
<a name="vocabulary-filtering-create-examples"></a>

若要處理用於 的自訂詞彙篩選條件 Amazon Transcribe，請參閱下列範例：

### AWS 管理主控台
<a name="vocab-filter-create-console-batch"></a>

繼續前，請將您的自訂詞彙篩選儲存為文字 (\*.txt) 檔案。您可以選擇將檔案上傳至 儲存 Amazon S3 貯體。

1. 登入 [AWS 管理主控台](https://console.aws.amazon.com/transcribe/)。

1. 在導覽窗格中，選擇**詞彙篩選**。這會開啟**詞彙篩選**頁面，您可以在其中檢視現有的自訂詞彙篩選或建立新的詞彙篩選。

1. 選擇**建立詞彙篩選**。  
![Amazon Transcribe 主控台螢幕擷取畫面：「詞彙篩選條件」頁面。](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/vocab-filter-create-console.png)

   這會引導您前往**建立詞彙篩選**頁面。輸入新自訂詞彙篩選的名稱。

   選擇**詞彙輸入來源**下的**檔案上傳**(檔案上傳)或 **S3 位置**選項。然後指定自訂詞彙檔案的位置。  
![Amazon Transcribe 主控台螢幕擷取畫面：「建立詞彙篩選條件」頁面。](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/vocab-filter-create-console-upload.png)

1. 或者，將標籤新增至您的自訂詞彙篩選。完成所有欄位後，請選擇頁面底部的**建立詞彙篩選**。如果處理檔案時沒有錯誤，這會引導您回到**詞彙篩選**頁面。

   您的自訂詞彙篩選現在可以開始使用。

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

此範例使用 [create-vocabulary-filter](https://docs.aws.amazon.com/cli/latest/reference/transcribe/create-vocabulary-filter.html) 指令，將單字清單處理為可用的自訂詞彙篩選條件。如需詳細資訊，請參閱[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabularyFilter.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabularyFilter.html)。

**選項 1**：您可以使用 `words` 參數將單詞清單包含到請求中。

```
aws transcribe create-vocabulary-filter \ 
--vocabulary-filter-name {{my-first-vocabulary-filter}} \ 
--language-code {{en-US}} \ 
--words {{profane,offensive,Amazon,Transcribe}}
```

**選項 2**：您可以將單字清單儲存為文字檔案，並將其上傳至 Amazon S3 儲存貯體，然後使用 `vocabulary-filter-file-uri` 參數，在請求中加入檔案的 URI。

```
aws transcribe create-vocabulary-filter \ 
--vocabulary-filter-name {{my-first-vocabulary-filter}} \ 
--language-code {{en-US}} \ 
--vocabulary-filter-file-uri s3://{{amzn-s3-demo-bucket}}/{{my-vocabulary-filters}}/{{my-vocabulary-filter}}.txt
```

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

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

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

**選項 1**：您可以使用 `Words` 參數將單詞清單包含到請求中。

```
{
  "VocabularyFilterName": "{{my-first-vocabulary-filter}}",
  "LanguageCode": "{{en-US}}",
  "Words": [
        "{{profane}}","{{offensive}}","{{Amazon}}","{{Transcribe}}"
  ]
}
```

**選項 2**：您可以將單字清單儲存為文字檔案，並將其上傳至 Amazon S3 儲存貯體，然後使用 `VocabularyFilterFileUri` 參數，在請求中加入檔案的 URI。

```
{
  "VocabularyFilterName": "{{my-first-vocabulary-filter}}",
  "LanguageCode": "{{en-US}}",
  "VocabularyFilterFileUri": "s3://{{amzn-s3-demo-bucket}}/{{my-vocabulary-filters}}/{{my-vocabulary-filter}}.txt"
}
```

**注意**  
如果您的請求中包含 `VocabularyFilterFileUri`，則無法使用 `Words`；您必須選擇其中一個。

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

此範例使用 適用於 Python (Boto3) 的 AWS SDK 來建立使用 [create\_vocabulary\_filter 方法的自訂詞彙篩選條件](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/transcribe.html#TranscribeService.Client.create_vocabulary_filter)。如需詳細資訊，請參閱[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabularyFilter.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_CreateVocabularyFilter.html)。

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

**選項 1**：您可以使用 `Words` 參數將單詞清單包含到請求中。

```
from __future__ import print_function
import time
import boto3
transcribe = boto3.client('transcribe', '{{us-west-2}}')
vocab_name = "{{my-first-vocabulary-filter}}"
response = transcribe.create_vocabulary_filter(
    LanguageCode = '{{en-US}}',
    VocabularyFilterName = vocab_name,
    Words = [        
        '{{profane}}','{{offensive}}','{{Amazon}}','{{Transcribe}}'
    ]
)
```

**選項 2**：您可以將單字清單儲存為文字檔案，並將其上傳至 Amazon S3 儲存貯體，然後使用 `VocabularyFilterFileUri` 參數，在請求中加入檔案的 URI。

```
from __future__ import print_function
import time
import boto3
transcribe = boto3.client('transcribe', '{{us-west-2}}')
vocab_name = "{{my-first-vocabulary-filter}}"
response = transcribe.create_vocabulary_filter(
    LanguageCode = '{{en-US}}',
    VocabularyFilterName = vocab_name,
    VocabularyFilterFileUri = 's3://{{amzn-s3-demo-bucket}}/{{my-vocabulary-filters}}/{{my-vocabulary-filter}}.txt'
)
```

**注意**  
如果您的請求中包含 `VocabularyFilterFileUri`，則無法使用 `Words`；您必須選擇其中一個。

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