

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

# 啟用發言者分隔
<a name="conversation-diarization-med"></a>

若要在 Amazon Transcribe Medical 中啟用發言者分割，請使用*發言者日記*。這讓您可以查看在轉錄輸出中患者說的內容以及臨床醫生說的內容。

當您啟用發言者日記時， Amazon Transcribe Medical 會使用每個發言者的唯一識別符來標記每個發言者*表達用語*。*表達用語*是語音單位，通常會以靜音區分其他表達用語。在批次轉錄中，臨床醫生的表達用語會收到 `spk_0` 的標示而患者會收到 `spk_1` 的標示。

如果一個發言者的表達用語與另一位發言者的表達用語重疊， Amazon Transcribe Medical 會按照開始時間在轉錄中排序。輸入音訊中重疊的表達用語在轉錄輸出中不會重疊。

您使用批次轉錄作業或即時串流轉錄音訊檔案時，您可以啟用發言者日記功能。

**Topics**
+ [在批次轉錄中啟用發言者分隔](conversation-diarization-batch-med.md)
+ [在即時串流中啟用發言者分隔](conversation-diarization-streaming-med.md)

# 在批次轉錄中啟用發言者分隔
<a name="conversation-diarization-batch-med"></a>

您可以在批次轉錄作業中使用 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html) API 或 AWS 管理主控台。這讓您可以在臨床醫生和患者對話中，進行每個發言者的分隔，並確定在轉錄輸出中發言者說的內容。

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

若要使用 AWS 管理主控台 在轉錄任務中啟用發言者日記，您可以啟用音訊識別，然後啟用發言者分割。

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

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

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

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

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

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

1. 對於**音訊識別類型**，請選擇**發言者分隔**。

1. 對於**最大發言者數量**，請輸入您認為在音訊檔案中說話的最大發言者數量。

1. 選擇**建立**。

## API
<a name="conversation-diarization-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. 對於 `MedicalTranscriptionJobName`，請指定在 AWS 帳戶中唯一的名稱。

  1. 對於 `LanguageCode`，請指定與音訊檔案中所說語言相對應的語言代碼。

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

  1. 對於 `Specialty`，請指定在音訊檔案中說話的臨床醫生的醫療專科。

  1. 對於 `Type`，請指定 `CONVERSATION`。

  1. 對於 `OutputBucketName`，指定儲存 Amazon S3 貯體以存放轉錄結果。

  1. 對於 `Settings` 物件，請指定下列項目：

     1. `ShowSpeakerLabels` – `true`.

     1. `MaxSpeakerLabels`— 介於 2 和 10 之間的整數，表示您認為在音訊中說話的發言者數量。

下列請求使用 適用於 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_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 = 'my-output-files/', 
    LanguageCode = 'en-US',
    Specialty = 'PRIMARYCARE',
    Type = 'CONVERSATION',
    OutputBucketName = 'amzn-s3-demo-bucket',
Settings = {'ShowSpeakerLabels': True,
         'MaxSpeakerLabels': 2
         }
         )
while True:
    status = transcribe.get_medical_transcription_job(MedicalTranscriptionJobName = job_name)
    if status['MedicalTranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:
        break
    print("Not ready yet...")
    time.sleep(5)
print(status)
```

下列範例程式碼示範啟用發言者分隔的轉錄作業的轉錄結果。

```
{
    "jobName": "job ID",
    "accountId": "111122223333",
    "results": {
        "transcripts": [
            {
                "transcript": "Professional answer."
            }
        ],
        "speaker_labels": {
            "speakers": 1,
            "segments": [
                {
                    "start_time": "0.000000",
                    "speaker_label": "spk_0",
                    "end_time": "1.430",
                    "items": [
                        {
                            "start_time": "0.100",
                            "speaker_label": "spk_0",
                            "end_time": "0.690"
                        },
                        {
                            "start_time": "0.690",
                            "speaker_label": "spk_0",
                            "end_time": "1.210"
                        }
                    ]
                }
            ]
        },
        "items": [
            {
                "start_time": "0.100",
                "end_time": "0.690",
                "alternatives": [
                    {
                        "confidence": "0.8162",
                        "content": "Professional"
                    }
                ],
                "type": "pronunciation"
            },
            {
                "start_time": "0.690",
                "end_time": "1.210",
                "alternatives": [
                    {
                        "confidence": "0.9939",
                        "content": "answer"
                    }
                ],
                "type": "pronunciation"
            },
            {
                "alternatives": [
                    {
                        "content": "."
                    }
                ],
                "type": "punctuation"
            }
        ]
    },
    "status": "COMPLETED"
}
```

## AWS CLI
<a name="diarization-batch-cli"></a>

**轉錄執行初級護理的臨床醫生與患者對話的音訊檔案 (AWS CLI)**
+ 執行下列程式碼。

  ```
                      
  aws transcribe start-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":{
            "ShowSpeakerLabels": true,
            "MaxSpeakerLabels": 2
          }
  }
  ```

# 在即時串流中啟用發言者分隔
<a name="conversation-diarization-streaming-med"></a>

若要在即時串流中分割發言者並標記其語音，請使用 AWS 管理主控台 或串流請求。發言者分隔最適合兩個至五個發言者的串流。雖然 Amazon Transcribe Medical 可以在串流中分割超過五個發言者，但如果超過該數字，則分割區的準確性會降低。

若要開始 HTTP/2 請求，請使用 [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。若要開始 WebSocket 請求，請使用預先簽署的 URI。URI 包含設定應用程式與 Amazon Transcribe Medical 設定雙向通訊所需的資訊。

## 在麥克風語音中啟用發言者分隔 (AWS 管理主控台)
<a name="conversation-diarization-console"></a>

您可以使用 AWS 管理主控台 來啟動臨床醫生與患者對話的即時串流，或即時對麥克風說話的口述。

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

1. 在導覽窗格中，針對 Amazon Transcribe 醫療選擇**即時轉錄**。

1. 對於**音訊輸入類型**，選擇您要轉錄的醫療語音類型。

1. 對於**其他設定**，選擇**發言者分隔**。

1. 選擇**開始串流**以開始轉錄您的即時音訊。

1. 對著麥克風說話。

## 在 HTTP/2 串流中啟用發言者分隔
<a name="conversation-diarization-med-http2"></a>

若要在醫療對話的 HTTP/2 串流中啟用發言者區隔，請使用 [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 並指定下列項目：
+ 對於 `LanguageCode`，指定與串流中的語言相對應的語言代碼。有效值為 `en-US`。
+ 對於 `MediaSampleHertz`，指定音訊的取樣率。
+ 對於 `Specialty`，指定提供者的醫療專科。
+ `ShowSpeakerLabel` – `true`

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

## 在 WebSocket 請求中啟用發言者分隔
<a name="conversation-diarization-med-websocket"></a>

若要使用 API 以分隔 WebSocket 串流中的發言者，請使用下列格式以建立預先簽署的 URI，開始 WebSocket 請求並設定 `show-speaker-label` 為 `true`。

```
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
&specialty=medicalSpecialty
&type=CONVERSATION
&vocabulary-name=vocabularyName
&show-speaker-label=boolean
```

下列程式碼示範串流請求的截斷範例回應。

```
{
  "Transcript": {
    "Results": [
      {
        "Alternatives": [
          {
            "Items": [
              {
                "Confidence": 0.97,
                "Content": "From",
                "EndTime": 18.98,
                "Speaker": "0",
                "StartTime": 18.74,
                "Type": "pronunciation",
                "VocabularyFilterMatch": false
              },
              {
                "Confidence": 1,
                "Content": "the",
                "EndTime": 19.31,
                "Speaker": "0",
                "StartTime": 19,
                "Type": "pronunciation",
                "VocabularyFilterMatch": false
              },
              {
                "Confidence": 1,
                "Content": "last",
                "EndTime": 19.86,
                "Speaker": "0",
                "StartTime": 19.32,
                "Type": "pronunciation",
                "VocabularyFilterMatch": false
              },
             ...
              {
                "Confidence": 1,
                "Content": "chronic",
                "EndTime": 22.55,
                "Speaker": "0",
                "StartTime": 21.97,
                "Type": "pronunciation",
                "VocabularyFilterMatch": false
              },
              ...
                "Confidence": 1,
                "Content": "fatigue",
                "EndTime": 24.42,
                "Speaker": "0",
                "StartTime": 23.95,
                "Type": "pronunciation",
                "VocabularyFilterMatch": false
              },
              {
                "EndTime": 25.22,
                "StartTime": 25.22,
                "Type": "speaker-change",
                "VocabularyFilterMatch": false
              },
              {
                "Confidence": 0.99,
                "Content": "True",
                "EndTime": 25.63,
                "Speaker": "1",
                "StartTime": 25.22,
                "Type": "pronunciation",
                "VocabularyFilterMatch": false
              },
              {
                "Content": ".",
                "EndTime": 25.63,
                "StartTime": 25.63,
                "Type": "punctuation",
                "VocabularyFilterMatch": false
              }
            ],
            "Transcript": "From the last note she still has mild sleep deprivation and chronic fatigue True."
          }
        ],
        "EndTime": 25.63,
        "IsPartial": false,
        "ResultId": "XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
        "StartTime": 18.74
      }
    ]
  }
}
```

Amazon Transcribe Medical 會根據自然語音區段來中斷傳入的音訊串流，例如喇叭變更或音訊暫停。系統會漸進式地將轉錄傳回您的應用程式，每次回應皆會包含更多轉錄的語音，直到整個區段轉錄完成。上述程式碼是完全轉錄語音區段的截斷範例。只有完全轉錄的區段會顯示發言者標籤。

下列清單顯示串流轉錄輸出中物件和參數的組織。

**`Transcript`**  
每個語音區段都有自己的 `Transcript` 物件。

**`Results`**  
每個 `Transcript` 物件都有自己的 `Results` 物件。此物件包含 `isPartial` 欄位。其值為 `false` 時，傳回的結果會針對整個語音區段。

**`Alternatives`**  
每個 `Results` 物件都有一個 `Alternatives` 物件。

**`Items`**  
每個 `Alternatives` 物件都有自己的 `Items` 物件，其中包含轉錄輸出中每個單字和標點符號的相關資訊。當您啟用發言者分割時，每個單字都有完整轉錄語音區段的`Speaker`標籤。 Amazon Transcribe Medical 使用此標籤為串流中的每個發言者指派唯一的整數。值為 `speaker-change` 的 `Type` 參數代表使用者已經停止說話，而另一個使用者即將開始。

**`Transcript`**  
每個項目物件都包含轉錄的語音區段作為 `Transcript` 欄位的值。

如需 WebSocket 請求的詳細資訊，請參閱 [設定 WebSocket 串流](streaming-setting-up.md#streaming-websocket)。