

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# カスタム言語モデルの使用
<a name="custom-language-models-using"></a>

カスタム言語モデルを作成したら、それを文字起こしリクエストに含めることができます。例については、以下のセクションを参照してください。

リクエストに含めるモデルの言語は、メディアに指定した言語コードと一致する必要があります。言語が一致しない場合、カスタム言語モデルは文字起こしに適用されず、警告やエラーも発生しません。

## バッチ文字起こしでカスタム言語モデルを使用する
<a name="custom-language-models-using-batch"></a>

バッチ文字起こしでカスタム言語モデルを使用するには、以下の例を参照してください。

### AWS マネジメントコンソール
<a name="model-console-batch"></a>

1. [AWS マネジメントコンソール](https://console.aws.amazon.com/transcribe/) にサインインします。

1. ナビゲーションペインで、[**文字起こしジョブ**] を選択後、[**ジョブの作成**] (右上) を選択します。これにより、「**ジョブの詳細を指定**」ページが開きます。

1. [**ジョブ設定**] パネルの [**モデルタイプ**] で、[**カスタム言語モデル**] ボックスを選択します。  
![Amazon Transcribe コンソールのスクリーンショット: 「ジョブ設定」ページ。](http://docs.aws.amazon.com/ja_jp/transcribe/latest/dg/images/clm-console.png)

   また、ドロップダウンメニューから入力言語を選択する必要があります。  
![Amazon Transcribe コンソールのスクリーンショット: ドロップダウン言語メニューを示す「ジョブ設定」ページ。](http://docs.aws.amazon.com/ja_jp/transcribe/latest/dg/images/clm-console-language.png)

1. **カスタムモデルの選択**で、ドロップダウンメニューから [既存のカスタム言語モデル] を選択するか、[**新しいカスタム言語モデルを作成**] を選択します。

   入力**データ**パネルに入力ファイル Amazon S3 の場所を追加します。

1. [**次へ**] を選択すると、追加の設定オプションが表示されます。

   [**ジョブの作成**] を選択して、文字起こしジョブを実行します。

### AWS CLI
<a name="model-using-cli"></a>

この例では、[start-transcription-job](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/transcribe/start-transcription-job.html) コマンドと `ModelSettings` パラメータ、`VocabularyName` サブパラメータを使用します。詳細については、「[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html)」および「[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ModelSettings.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ModelSettings.html)」を参照してください。

```
aws transcribe start-transcription-job \
--region {{us-west-2}} \
--transcription-job-name {{my-first-transcription-job}} \
--media MediaFileUri=s3://{{amzn-s3-demo-bucket}}/{{my-input-files}}/{{my-media-file}}.{{flac}} \
--output-bucket-name {{amzn-s3-demo-bucket}} \
--output-key {{my-output-files}}/ \
--language-code {{en-US}} \
--model-settings LanguageModelName={{my-first-language-model}}
```

以下は、[start-transcription-job](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/transcribe/start-transcription-job.html)コマンド、およびそのジョブでカスタム言語モデルを含むリクエストボディを使用した別の例です。

```
aws transcribe start-transcription-job \
--region {{us-west-2}} \
--cli-input-json file://{{my-first-model-job}}.json
```

ファイル *my-first-model-job.json* には、次のリクエストボディが含まれています。

```
{
  "TranscriptionJobName": "{{my-first-transcription-job}}",
  "Media": {
        "MediaFileUri": "s3://{{amzn-s3-demo-bucket}}/{{my-input-files}}/{{my-media-file}}.{{flac}}"
  },
  "OutputBucketName": "{{amzn-s3-demo-bucket}}",
  "OutputKey": "{{my-output-files}}/", 
  "LanguageCode": "{{en-US}}",
  "ModelSettings": {
        "LanguageModelName": "{{my-first-language-model}}"
   }
}
```

### AWS SDK for Python (Boto3)
<a name="model-using-python-batch"></a>

この例では、 を使用して AWS SDK for Python (Boto3) 、[start\_transcription\_job](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/transcribe.html#TranscribeService.Client.start_transcription_job) メソッドの `ModelSettings`引数を使用してカスタム言語モデルを含めます。詳細については、「[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html)」および「[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ModelSettings.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ModelSettings.html)」を参照してください。

機能固有の例、シナリオ例、クロスサービス例など、 AWS SDKs[SDK を使用した Amazon Transcribe のコード例 AWS SDKs](service_code_examples.md)「」の章を参照してください。

```
from __future__ import print_function
import time
import boto3
transcribe = boto3.client('transcribe', '{{us-west-2}}')
job_name = "{{my-first-transcription-job}}"
job_uri = "s3://{{amzn-s3-demo-bucket}}/{{my-input-files}}/{{my-media-file}}.{{flac}}"
transcribe.start_transcription_job(
    TranscriptionJobName = job_name,
    Media = {
        'MediaFileUri': job_uri
    },
    OutputBucketName = '{{amzn-s3-demo-bucket}}',
    OutputKey = '{{my-output-files}}/', 
    LanguageCode = '{{en-US}}', 
    ModelSettings = {
        'LanguageModelName': '{{my-first-language-model}}' 
   }
)

while True:
    status = transcribe.get_transcription_job(TranscriptionJobName = job_name)
    if status['TranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:
        break
    print("Not ready yet...")
    time.sleep(5)
print(status)
```

## ストリーミング文字起こしでカスタム言語モデルを使用する
<a name="custom-language-models-using-stream"></a>

ストリーミング文字起こしでカスタム言語モデルを使用するには、以下の例を参照してください。

### AWS マネジメントコンソール
<a name="model-console-stream"></a>

1. [AWS マネジメントコンソール](https://console.aws.amazon.com/transcribe/) にサインインします。

1. ナビゲーションペインで、[**リアルタイム文字起こし**] を選択します。**カスタマイズ**までスクロールして、最小化されている場合はこのフィールドを展開します。  
![Amazon Transcribe コンソールのスクリーンショット：「リアルタイム文字起こし」ページ。](http://docs.aws.amazon.com/ja_jp/transcribe/latest/dg/images/stream-main.png)

1. [**カスタム言語モデル**] をオンにして、ドロップダウンメニューからモデルを選択します。  
![Amazon Transcribe コンソールのスクリーンショット: 展開された「カスタマイズ」パネル。](http://docs.aws.amazon.com/ja_jp/transcribe/latest/dg/images/model-stream2.png)

   ストリームに適用するその他の設定を含めます。

1. これで、ストリームを書き起こす準備ができました。[**ストリーミングを開始する**] を選択し、話し始めます。ディクテーションを終了するには、[**ストリーミングを停止する**] を選択します。

### HTTP/2 ストリーム
<a name="model-using-http2"></a>

この例では、カスタム言語モデルで HTTP/2 リクエストを作成します。での HTTP/2 ストリーミングの使用の詳細については Amazon Transcribe、「」を参照してください[HTTP/2 ストリームの設定](streaming-setting-up.md#streaming-http2)。固有のパラメータとヘッダーの詳細については Amazon Transcribe、「」を参照してください[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartStreamTranscription.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartStreamTranscription.html)。

```
POST /stream-transcription HTTP/2
host: transcribestreaming.{{us-west-2}}.amazonaws.com
X-Amz-Target: com.amazonaws.transcribe.Transcribe.{{StartStreamTranscription}}
Content-Type: application/vnd.amazon.eventstream
X-Amz-Content-Sha256: {{string}}
X-Amz-Date: {{20220208}}T{{235959}}Z
Authorization: AWS4-HMAC-SHA256 Credential={{access-key}}/{{20220208}}/{{us-west-2}}/transcribe/aws4_request, SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target;x-amz-security-token, Signature={{string}}
x-amzn-transcribe-language-code: {{en-US}}
x-amzn-transcribe-media-encoding: {{flac}}
x-amzn-transcribe-sample-rate: {{16000}}      
x-amzn-transcribe-language-model-name: {{my-first-language-model}}
transfer-encoding: chunked
```

パラメータ定義は [API リファレンス](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Reference.html)にあります。すべての AWS API オペレーションに共通のパラメータは、[「共通パラメータ](https://docs.aws.amazon.com/transcribe/latest/APIReference/CommonParameters.html)」セクションに記載されています。

### WebSocket ストリーム
<a name="model-using-websocket"></a>

この例では、WebSocket ストリーミングでカスタム言語モデルを適用する署名付き URL を作成します。読みやすくするために、改行が追加されています。で WebSocket ストリームを使用する方法の詳細については Amazon Transcribe、「」を参照してください[WebSocket ストリームの設定](streaming-setting-up.md#streaming-websocket)。パラメータの詳細については、「[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartStreamTranscription.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartStreamTranscription.html)」を参照してください。

```
GET wss://transcribestreaming.{{us-west-2}}.amazonaws.com:8443/stream-transcription-websocket?
&X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Credential={{AKIAIOSFODNN7EXAMPLE}}%2F{{20220208}}%2F{{us-west-2}}%2F{{transcribe}}%2Faws4_request
&X-Amz-Date={{20220208}}T{{235959}}Z
&X-Amz-Expires={{300}}
&X-Amz-Security-Token={{security-token}}
&X-Amz-Signature={{string}}
&X-Amz-SignedHeaders=content-type%3Bhost%3Bx-amz-date
&language-code={{en-US}}
&media-encoding={{flac}}
&sample-rate={{16000}}    
&language-model-name={{my-first-language-model}}
```

パラメータ定義は [API リファレンス](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Reference.html)にあります。すべての AWS API オペレーションに共通のパラメータは、[「共通パラメータ](https://docs.aws.amazon.com/transcribe/latest/APIReference/CommonParameters.html)」セクションに記載されています。