

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

# 轉錄多聲道音訊
<a name="conversation-channel-id-med"></a>

如果您的音訊檔案或串流有多個頻道，您可以使用*頻道識別*來轉錄每個頻道的語音。 Amazon Transcribe Medical 會分別轉錄每個頻道的語音。它將每個聲道的獨立轉錄與單一轉錄輸出結合。

使用聲道識別以識別音訊中不同的聲道，並從每個聲道轉錄語音。在通話者和客服人員案例等情況下啟用此功能。使用此功能可區分通話者與執行藥物安全監控的聯絡中心的錄音或串流中的客服人員。

您可以為批次處理和即時串流，啟用聲道識別。下列清單描述如何為每個方法啟用。
+ 批次轉錄 – AWS 管理主控台 和 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html) API
+ 串流轉錄 — WebSocket 串流和 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartMedicalStreamTranscription.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartMedicalStreamTranscription.html) API

## 轉錄多聲道音訊檔案
<a name="conversation-channel-id-med-batch"></a>

當您轉錄音訊檔案時， Amazon Transcribe Medical 會傳回每個頻道*的項目*清單。項目是轉錄的單字或標點符號。每個單字都有開始時間和結束時間。如果聲道上的使用者與不同聲道上的某個人說話，則每個聲道項目的開始時間和結束時間會重疊，且個人彼此交談時間也會重疊。

依預設，您可以轉錄有兩個聲道的音訊檔案。如果您需要轉錄有兩個以上聲道的檔案，可以要求提高配額。如需請求提高配額的詳細資訊，請參閱 [AWS 服務 配額](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html)。

若要在批次轉錄任務中轉錄多聲道音訊，請使用 AWS 管理主控台 或 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html) API。

### AWS 管理主控台
<a name="channel-id-batch-med-console"></a>

若要使用 AWS 管理主控台 在批次轉錄任務中啟用頻道識別，您可以啟用音訊識別，然後啟用頻道識別。頻道識別是 中音訊識別的子集 AWS 管理主控台。

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

1. 在導覽窗格的 Amazon Transcribe Medical 下，選擇**轉錄任務**。

1. 選擇**建立作業**。

1. 在**指定作業詳細資訊**頁面上，提供轉錄作業的相關資訊。

1. 選擇**下一步**。

1. 啟用**音訊識別**。

1. 對於**音訊識別類型**，請選擇**聲道識別**。

1. 選擇**建立**。

### API
<a name="channel-id-batch-med-api"></a>

**轉錄多聲道音訊檔案 (API)**
+ 對於 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html) API，請指定以下項目。

  1. 對於 `TranscriptionJobName`，指定 AWS 帳戶的唯一名稱。

  1. 對於 `LanguageCode`，請指定與音訊檔案中所說語言相對應的語言代碼。有效值為 `en-US`。

  1. 對於 `Media` 物件的 `MediaFileUri` 參數，指定您要轉錄的媒體檔案名稱。

  1. 對於 `Settings` 物件，設定 `ChannelIdentification` 為 `true`。

以下是使用 適用於 Python (Boto3) 的 AWS SDK的範例請求。

```
from __future__ import print_function
import time
import boto3
transcribe = boto3.client('transcribe', 'us-west-2')
job_name = "my-first-transcription-job"
job_name = "my-first-med-transcription-job"
job_uri = "s3://amzn-s3-demo-bucket/my-input-files/my-media-file.flac"
transcribe.start_medical_transcription_job(
      MedicalTranscriptionJobName = job_name,
      Media = {
        'MediaFileUri': job_uri
      },
      OutputBucketName = 'amzn-s3-demo-bucket',
      OutputKey = 'output-files/',
      LanguageCode = 'en-US',
      Specialty = 'PRIMARYCARE',
      Type = 'CONVERSATION',
      Settings = {
        'ChannelIdentification': True
      }
)
while True:
    status = transcribe.get_transcription_job(MedicalTranscriptionJobName = job_name)
    if status['MedicalTranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:
        break
    print("Not ready yet...")
    time.sleep(5)
print(status)
```

### AWS CLI
<a name="channel-id-med-cli"></a>

**使用批次轉錄作業轉錄多聲道音訊檔案 (AWS CLI)**
+ 執行下列程式碼。

  ```
                      
  aws transcribe start-medical-transcription-job \
  --region us-west-2 \
  --cli-input-json file://example-start-command.json
  ```

  以下是 `example-start-command.json` 的程式碼。

  ```
  {
        "MedicalTranscriptionJobName": "my-first-med-transcription-job",        
        "Media": {
            "MediaFileUri": "s3://amzn-s3-demo-bucket/my-input-files/my-audio-file.flac"
        },
        "OutputBucketName": "amzn-s3-demo-bucket",
        "OutputKey": "my-output-files/", 
        "LanguageCode": "en-US",
        "Specialty": "PRIMARYCARE",
        "Type": "CONVERSATION",
  
          "Settings":{
            "ChannelIdentification": true
          }
  }
  ```

下列程式碼示範在兩個聲道有對話的音訊檔案的轉錄輸出。

```
{
  "jobName": "job id",
  "accountId": "111122223333",
  "results": {
    "transcripts": [
      {
        "transcript": "When you try ... It seems to ..."
      }
    ],
    "channel_labels": {
      "channels": [
        {
          "channel_label": "ch_0",
          "items": [
            {
              "start_time": "12.282",
              "end_time": "12.592",
              "alternatives": [
                {
                  "confidence": "1.0000",
                  "content": "When"
                }
              ],
              "type": "pronunciation"
            },
            {
              "start_time": "12.592",
              "end_time": "12.692",
              "alternatives": [
                {
                  "confidence": "0.8787",
                  "content": "you"
                }
              ],
              "type": "pronunciation"
            },
            {
              "start_time": "12.702",
              "end_time": "13.252",
              "alternatives": [
                {
                  "confidence": "0.8318",
                  "content": "try"
                }
              ],
              "type": "pronunciation"
            },
            ...
         ]
      },
      {
          "channel_label": "ch_1",
          "items": [
            {
              "start_time": "12.379",
              "end_time": "12.589",
              "alternatives": [
                {
                  "confidence": "0.5645",
                  "content": "It"
                }
              ],
              "type": "pronunciation"
            },
            {
              "start_time": "12.599",
              "end_time": "12.659",
              "alternatives": [
                {
                  "confidence": "0.2907",
                  "content": "seems"
                }
              ],
              "type": "pronunciation"
            },
            {
              "start_time": "12.669",
              "end_time": "13.029",
              "alternatives": [
                {
                  "confidence": "0.2497",
                  "content": "to"
                }
              ],
              "type": "pronunciation"
            },
            ...
        ]
    }
}
```

## 轉錄多聲道音訊串流
<a name="conversation-channel-id-med-stream"></a>

您可以使用 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartMedicalStreamTranscription.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartMedicalStreamTranscription.html) API 從 HTTP/2 或 WebSocket 串流中的不同聲道轉錄音訊。

依預設，您可以使用兩個聲道轉錄串流。如果您需要轉錄有兩個以上聲道的串流，可以要求提高配額。如需請求提高配額的詳細資訊，請參閱 [AWS Service Quotas](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html)。

### 在 HTTP/2 串流中轉錄多聲道音訊
<a name="conversation-channel-id-http2"></a>

若要轉錄 HTTP/2 串流中的多聲道音訊，請使用 [StartMedicalStreamTranscription](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartMedicalStreamTranscription.html) API 並指定下列項目：
+ `LanguageCode` — 音訊的語言代碼。有效值為 `en-US`。
+ `MediaEncoding` — 音訊的編碼。有效值為 `ogg-opus`、`flac` 和 `pcm`。
+ `EnableChannelIdentification` – `true`
+ `NumberOfChannels` — 您串流音訊中聲道的數量。

如需設定 HTTP/2 串流以轉錄醫療對話的詳細資訊，請參閱 [設定 HTTP/2 串流](streaming-setting-up.md#streaming-http2)。

### 轉錄 WebSocket 串流中的多聲道音訊
<a name="channel-id-med-websocket"></a>

若要分隔 WebSocket 串流中的發言者，請使用下列格式以建立預先簽署的 URI 並開始 WebSocket 請求。指定 `enable-channel-identification` 為 `true` 和 `number-of-channels` 串流中的聲道數量。預先簽章的 URI 包含設定應用程式與 Amazon Transcribe Medical 之間的雙向通訊所需的資訊。

```
GET wss://transcribestreaming.us-west-2.amazonaws.com:8443/medical-stream-transcription-websocket
?language-code=languageCode
&X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Credential=AKIAIOSFODNN7EXAMPLE%2F20220208%2Fus-west-2%2Ftranscribe%2Faws4_request
&X-Amz-Date=20220208T235959Z
&X-Amz-Expires=300
&X-Amz-Security-Token=security-token
&X-Amz-Signature=Signature Version 4 signature
&X-Amz-SignedHeaders=host
&media-encoding=flac
&sample-rate=16000
&session-id=sessionId
&enable-channel-identification=true
&number-of-channels=2
```

您可以在 [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 請求的詳細資訊，請參閱 [設定 WebSocket 串流](streaming-setting-up.md#streaming-websocket)。

### 多聲道串流輸出
<a name="streaming-med-output"></a>

對於 HTTP/2 和 WebSocket 請求，串流轉錄的輸出相同。以下為範例輸出。

```
{
    "resultId": "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX",
    "startTime": 0.11,
    "endTime": 0.66,
    "isPartial": false,
    "alternatives": [
        {
            "transcript": "Left.",
            "items": [
                {
                    "startTime": 0.11,
                    "endTime": 0.45,
                    "type": "pronunciation",
                    "content": "Left",
                    "vocabularyFilterMatch": false
                },
                {
                    "startTime": 0.45,
                    "endTime": 0.45,
                    "type": "punctuation",
                    "content": ".",
                    "vocabularyFilterMatch": false
                }
            ]
        }
    ],
    "channelId": "ch_0"
}
```

對於每個語音區段，都有一個 `channelId` 標記，指出該語音所屬的聲道。