

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

# 使用串流轉錄進行語言識別
<a name="lang-id-stream"></a>

串流語言識別可以識別媒體串流中說的主要語言。 Amazon Transcribe 需要至少一秒鐘的語音來識別語言。

如果您的串流僅包含一種語言，您可以啟用單一語言識別功能，識別媒體檔案中所使用的優勢語言，並僅使用此語言建立文字記錄。

如果您的串流包含一種以上的語言，您可以啟用多語言識別功能，識別串流中所使用的所有語言，並使用每種識別的語言建立您的文字記錄。請注意，會產生多語言文字記錄。您可以使用其他 服務來翻譯文字記錄 Amazon Transcribe，例如 。

若要使用串流語言識別，您必須提供至少兩個語言代碼，而且每個串流只能選擇一種語言方言。這表示您無法選擇 `en-US` 和 `en-AU` 作為相同轉錄的語言選項。

您也可以選擇從您提供的語言代碼集中，選擇偏好的語言。新增偏好語言可加速語言識別流程，這對於短音訊片段很實用。

**重要**  
如果您提供的語言代碼都不符合音訊中識別的語言， 會從您指定的語言代碼 Amazon Transcribe 中選取最接近的語言。然後，它會產生該語言的文字記錄。例如，如果您的媒體是美式英文 (`en-US`)`fr-FR`，並且您提供 Amazon Transcribe 語言代碼 `zh-CN`、 和 `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. 在導覽窗格中，選擇**即時轉錄**。向下捲動至**語言設定**，如果此欄位已最小化，請展開此欄位。  
![\[Amazon Transcribe 主控台螢幕擷取畫面：「即時轉錄」頁面上的摺疊「語言設定」索引標籤。\]](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/lang-id-stream1.png)

1. 選取**自動語言識別**或**自動多語言識別**。  
![\[Amazon Transcribe 主控台螢幕擷取畫面：展開的「語言設定」索引標籤。\]](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/lang-id-stream2.png)

1. 為您的轉錄提供至少兩個語言代碼。請注意，每種語言只能提供一種方言。例如，您無法同時選擇 `en-US` 和 `en-GB` 作為相同轉錄的語言選項。  
![\[Amazon Transcribe 主控台螢幕擷取畫面：語言代碼選擇下拉式選單。\]](http://docs.aws.amazon.com/zh_tw/transcribe/latest/dg/images/lang-id-stream3.png)

1. (選擇性) 從您在上一步中選擇的語言子集中，您可以為文字記錄選擇偏好的語言。  
![\[Amazon Transcribe 主控台螢幕擷取畫面：具有偏好語言選項的「語言設定」面板。\]](http://docs.aws.amazon.com/zh_tw/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>

此範例會建立預先簽署 URL，並在 WebSocket 串流中使用語言識別。已加入分行符號以提高可讀性。如需搭配 使用 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
```

此範例會建立預先簽署 URL，並在 WebSocket 串流中使用多語言識別。已加入分行符號以提高可讀性。如需搭配 使用 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)區段中。