

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

# 流式转录中的语言识别
<a name="lang-id-stream"></a>

流媒体语言识别可以识别您的媒体流中使用的主导语言。 Amazon Transcribe 需要至少一秒钟的语音才能识别语言。

如果流仅包含一种语言，您可以启用单语言识别，这会识别媒体文件中使用的主要语言并仅使用该语言创建转录。

如果流包含多种语言，您可以启用多语言识别，这会识别流中使用的所有语言，并使用每种识别的语言创建转录。请注意，这将会生成多语言转录。您可以使用其他服务，例如 Amazon Transcribe，来翻译您的成绩单。

要使用流式转录语言识别，您必须提供至少两个语言代码，并且对于每个音频流，每种语言只能选择一种语言方言。这表示，您不能为同一个转录选择 `en-US` 和 `en-AU` 作为语言选项。

您还可以选择从您提供的一组语言代码中选择一种首选语言。添加首选语言可以加快语言识别过程，这对于简短的音频片段很有帮助。

**重要**  
如果您提供的语言代码均不与音频中识别的语言相匹配，请从您指定的语言代码 Amazon Transcribe 中选择最接近的语言匹配项。然后，它会生成该语言的转录。例如，如果您的媒体 Amazon Transcribe 使用的是美国英语 (`en-US`)，并且您提供的语言代码`zh-CN``fr-FR``de-DE`、和， Amazon Transcribe 很可能会将您的媒体与德语 (`de-DE`) 匹配并生成德语转录。语言代码和说出的语言不匹配可能会导致转录不准确，因此我们建议在添加语言代码时要小心谨慎。

如果您的媒体包含两个频道，则 Amazon Transcribe 可以识别每个频道中使用的主导语言。在这种情况下，将 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Settings.html#transcribe-Type-Settings-ChannelIdentification](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Settings.html#transcribe-Type-Settings-ChannelIdentification) 参数设置为 `true`，每个声道将分别转录。注意，此参数的默认值为 `false`。如果您不对其进行更改，则只会转录第一个声道，并且只识别一种语言。

流式转录语言识别不能与自定义语言模型或编辑结合使用。如果将语言识别与其它特征结合使用，则只能使用这些特征支持的语言以及流式转录支持的语言。请参阅[支持的语言](supported-languages.md)。

**注意**  
PCM 和 FLAC 是唯一支持的用于流式转录语言识别的音频格式。对于多语言识别，仅支持 PCM。

## 识别多语言音频中的语言
<a name="multi-language-streaming"></a>

多语言识别适用于多语言流，并为您提供反映流中使用的所有支持的语言的转录。这就表示，如果发言者在对话中变换语言，或者如果每个参与者说的是不同的语言，则您的转录输出会正确检测并转录每种语言。

例如，如果流包含交替使用美国英语 (`en-US`) 和印地语 (`hi-IN`) 的双语发言者，则多语言识别可以识别所说的美国英语并转录为 `en-US`，并将所说的印地语转录为 `hi-IN`。这不同于单语言识别，后者只使用一种主要语言来创建转录。在这种情况下，主导语言以外的任何语言都会被错误地转录。

**注意**  
多语言识别目前不支持编辑和自定义语言模型。

## 在流式转录媒体中使用语言识别
<a name="lang-id-stream-examples"></a>

您可以使用**AWS 管理控制台**、**HTTP/2** 或，在流媒体转录中使用自动语言识别 **WebSockets**；有关示例，请参阅以下内容：

### AWS 管理控制台
<a name="lang-id-console-stream"></a>

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

1. 在导航窗格中，选择 **Real-time transcription (实时转录)**。向下滚动到**语言设置**，如果该字段已最小化，则将其展开。  
![\[Amazon Transcribe 控制台屏幕截图：“实时转录” 页面上折叠的 “语言设置” 选项卡。\]](http://docs.aws.amazon.com/zh_cn/transcribe/latest/dg/images/lang-id-stream1.png)

1. 选择**自动语言识别**或**自动多语言识别**。  
![\[Amazon Transcribe 控制台屏幕截图：扩展的 “语言设置” 选项卡。\]](http://docs.aws.amazon.com/zh_cn/transcribe/latest/dg/images/lang-id-stream2.png)

1. 为您的转录提供至少两个语言代码。请注意，每种语言只能提供一种方言。例如，对于同一个转录，您不能同时选择 `en-US` 和 `en-GB` 作为语言选项。  
![\[Amazon Transcribe 控制台屏幕截图：语言代码选择下拉菜单。\]](http://docs.aws.amazon.com/zh_cn/transcribe/latest/dg/images/lang-id-stream3.png)

1. （可选）从您在上一步中选择的语言子集中，您可以为转录选择首选语言。  
![\[Amazon Transcribe 控制台屏幕截图：带有首选语言选项的 “语言设置” 面板。\]](http://docs.aws.amazon.com/zh_cn/transcribe/latest/dg/images/lang-id-stream4.png)

1. 您现在已准备就绪，可以转录音频流了。选择**开始流式转录**并开始讲话。要结束口述，请选择**停止流式转录**。

### HTTP/2 音频流
<a name="lang-id-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: 20220208T235959Z
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-media-encoding: flac
x-amzn-transcribe-sample-rate: 16000    
x-amzn-transcribe-identify-language: true
x-amzn-transcribe-language-options: en-US,de-DE
x-amzn-transcribe-preferred-language: en-US
transfer-encoding: chunked
```

该示例创建一个启用了多语言识别的 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: 20220208T235959Z
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-media-encoding: flac
x-amzn-transcribe-sample-rate: 16000    
x-amzn-transcribe-identify-multiple-languages: true
x-amzn-transcribe-language-options: en-US,de-DE
x-amzn-transcribe-preferred-language: en-US
transfer-encoding: chunked
```

如果在请求中使用 `identify-language` 或 `identify-multiple-languages`，您还必须包含 `language-options`。不能在同一个请求中同时使用 `language-code` 和 `identify-language`。

参数定义可在 [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="lang-id-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%2F20220208%2Fus-west-2%2Ftranscribe%2Faws4_request
&X-Amz-Date=20220208T235959Z
&X-Amz-Expires=300
&X-Amz-Security-Token=security-token
&X-Amz-Signature=string
&X-Amz-SignedHeaders=content-type%3Bhost%3Bx-amz-date
&media-encoding=flac
&sample-rate=16000
&identify-language=true
&language-options=en-US,de-DE
&preferred-language=en-US
```

此示例创建一个在 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%2F20220208%2Fus-west-2%2Ftranscribe%2Faws4_request
&X-Amz-Date=20220208T235959Z
&X-Amz-Expires=300
&X-Amz-Security-Token=security-token
&X-Amz-Signature=string
&X-Amz-SignedHeaders=content-type%3Bhost%3Bx-amz-date
&media-encoding=flac
&sample-rate=16000
&identify-multiple-languages=true
&language-options=en-US,de-DE
&preferred-language=en-US
```

如果在请求中使用 `identify-language` 或 `identify-multiple-languages`，您还必须包含 `language-options`。不能在同一个请求中同时使用 `language-code` 和 `identify-language`。

参数定义可在 [API 参考](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_Reference.html)中找到；所有 AWS API 操作的通用参数列在[常用参数](https://docs.aws.amazon.com/transcribe/latest/APIReference/CommonParameters.html)部分中。