

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 转录多声道音频
<a name="conversation-channel-id-med"></a>

如果您的音频文件或视频流具有多个频道，则可以使用*频道识别*来转录每个频道的语音。 Amazon Transcribe Medical 分别转录每个频道的演讲。它将每个声道的单独转录合并为一个转录输出。

使用声道识别来识别音频中的不同声道，并转录每个声道的语音。在来电者和座席场景等场景中启用此功能。使用它来区分执行药物安全监控的联络中心的录音或音频流中的来电者和座席。

您可以为批量转录和实时流式转录启用声道识别。以下列表描述了如何为每种方法启用该功能。
+ Batch 转录 — AWS 管理控制台 和 API [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html)
+ 直播转录 — WebSocket 直播和 API [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartMedicalStreamTranscription.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_streaming_StartMedicalStreamTranscription.html)

## 转录多声道音频文件
<a name="conversation-channel-id-med-batch"></a>

当您转录音频文件时，M Amazon Transcribe edical 会返回每个频道的*项目*列表。项目是转录的单词或标点符号。每个单词都有开始时间和结束时间。如果一个声道上的某个人与另一个声道上的一个人交谈，则当这些人互相交谈时，每个声道的项目的开始时间和结束时间会重叠。

默认情况下，您可以转录包含两个声道的音频文件。如果您需要转录的文件具有超过两个声道，则可以申请增加配额。有关请求增加配额的更多信息，请参阅 [AWS 服务 配额](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html)。

要在批量转录作业中转录多声道音频，请使用 AWS 管理控制台 或 API。[https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartMedicalTranscriptionJob.html)

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

要在 AWS 管理控制台 批量转录作业中使用启用频道识别，请先启用音频识别，然后启用频道识别。频道识别是中音频识别的一个子集 AWS 管理控制台。

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

1. 在导航窗格的 “ Amazon Transcribe 医疗” 下，选择 “**转录作业**”。

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>

您可以使用 API 在 HTTP/2 或 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)

默认情况下，您可以转录包含两个声道的音频流。如果您需要转录的音频流具有超过两个声道，则可以申请增加配额。有关请求增加配额的信息，请参阅 [AWS 服务配额](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` 标志，用于指示语音属于哪个声道。