使用 Docker 的語言識別容器

語音語言識別容器會偵測音訊檔案中說話的語言。 您可以使用中繼結果取得即時語音或批次音訊錄製。 在本文中,您將瞭解如何下載、安裝及執行語言識別容器。

注意

語音語言識別容器可在公開預覽中取得。 預覽中的容器仍在開發中,且不符合 Microsoft 的穩定性和支援需求。

如需必要條件、驗證容器正在執行、在相同主機上執行多個容器,以及執行中斷連線容器的詳細資訊,請參閱使用 Docker 安裝及執行語音容器

提示

若要取得最有用的結果,請使用語音轉換文字或自訂語音轉換文字容器的語音語言識別容器。

容器映像

您可以在 Microsoft Container Registry (MCR) Syndicate 中找到所有支援版本和地區設定的語音語言辨識容器映像。 它位於存放庫內 azure-cognitive-services/speechservices/ ,並命名為 language-detection

A screenshot of the search connectors and triggers dialog.

完整容器映像名稱為 mcr.microsoft.com/azure-cognitive-services/speechservices/language-detection 附加特定版本或附加 :latest 以取得最新版本。

版本 Path
最新 mcr.microsoft.com/azure-cognitive-services/speechservices/language-detection:latest
1.12.0 mcr.microsoft.com/azure-cognitive-services/speechservices/language-detection:1.12.0-amd64-preview

除了 latest以外的所有標籤都使用下列格式,且區分大小寫:

<major>.<minor>.<patch>-<platform>-<prerelease>

為了方便起見,標籤也以 JSON 格式提供。 本文包含容器路徑和標籤清單。 標籤不會依版本排序,但 "latest" 一律會包含在清單結尾,如下列程式碼片段所示:

{
  "name": "azure-cognitive-services/speechservices/language-detection",
  "tags": [
    "1.1.0-amd64-preview",
    "1.11.0-amd64-preview",
    "1.12.0-amd64-preview",
    "1.3.0-amd64-preview",
    "1.5.0-amd64-preview",
    <--redacted for brevity-->
    "1.8.0-amd64-preview",
    "latest"
  ]
}

使用 docker pull 取得容器映像

您需要必要條件,包括必要的硬體。 另請參閱 每個語音容器的建議資源 配置。

使用 docker pull 命令從 Microsoft Container Registry 下載容器映射:

docker pull mcr.microsoft.com/azure-cognitive-services/speechservices/language-detection:latest

使用 docker run 執行容器

使用 docker run 命令來執行容器。

下表代表各種 docker run 參數及其對應的描述:

參數 描述
{ENDPOINT_URI} 計量和計費需要端點。 如需詳細資訊,請參閱計費引數
{API_KEY} 需要 API 金鑰。 如需詳細資訊,請參閱計費引數

當您執行語音語言辨識容器時,請根據語言識別容器 需求和建議來設定埠、記憶體和 CPU。

以下為具有預留位置值的範例 docker run 命令。 您必須指定 ENDPOINT_URIAPI_KEY 值:

docker run --rm -it -p 5000:5003 --memory 1g --cpus 1 \
mcr.microsoft.com/azure-cognitive-services/speechservices/language-detection \
Eula=accept \
Billing={ENDPOINT_URI} \
ApiKey={API_KEY}

此命令:

  • 從容器映像執行語音語言識別容器。
  • 配置 1 個 CPU 核心和 1 GB 的記憶體。
  • 公開 TCP 連接埠 5000,並為容器配置虛擬 TTY。
  • 在容器結束時自動移除容器。 主計算機上仍可使用容器映像。

如需關於搭配語音容器執行 docker run 的詳細資訊,請參閱使用 Docker 安裝及執行語音容器

使用語音轉換文字容器執行

如果您想要使用 語音轉換文字 容器來執行語言辨識容器,您可以使用此 Docker 映像。 啟動這兩個容器之後,請使用此指令 docker run 來執行 speech-to-text-with-languagedetection-client

docker run --rm -v ${HOME}:/root -ti antsu/on-prem-client:latest ./speech-to-text-with-languagedetection-client ./audio/LanguageDetection_en-us.wav --host localhost --lport 5003 --sport 5000

增加並行呼叫數目可能會影響可靠性和延遲。 針對語言識別,我們建議最多使用 1 個 CPU 搭配 1 GB 記憶體的四個並行呼叫。 針對具有 2 個 CPU 和 2 GB 記憶體的主機,我們建議最多 6 個並行呼叫。

使用該容器

語音容器會提供 Websocket 型查詢端點 API,其可透過語音 SDK 和語音 CLI 來存取。 根據預設,語音 SDK 和語音 CLI 會使用公用語音服務。 若要使用容器,您必須變更初始化方法。

重要

當您搭配容器使用語音服務時,請務必使用主機驗證。 如果您設定金鑰和區域,則要求會移至公用語音服務。 來自語音服務的結果可能並非如您預期的結果。 來自已中斷連線容器的要求將會失敗。

不要使用此 Azure 雲端初始化設定:

var config = SpeechConfig.FromSubscription(...);

搭配容器主機使用此設定:

var config = SpeechConfig.FromHost(
    new Uri("http://localhost:5000"));

不要使用此 Azure 雲端初始化設定:

auto speechConfig = SpeechConfig::FromSubscription(...);

搭配容器主機使用此設定:

auto speechConfig = SpeechConfig::FromHost("http://localhost:5000");

不要使用此 Azure 雲端初始化設定:

speechConfig, err := speech.NewSpeechConfigFromSubscription(...)

搭配容器主機使用此設定:

speechConfig, err := speech.NewSpeechConfigFromHost("http://localhost:5000")

不要使用此 Azure 雲端初始化設定:

SpeechConfig speechConfig = SpeechConfig.fromSubscription(...);

搭配容器主機使用此設定:

SpeechConfig speechConfig = SpeechConfig.fromHost("http://localhost:5000");

不要使用此 Azure 雲端初始化設定:

const speechConfig = sdk.SpeechConfig.fromSubscription(...);

搭配容器主機使用此設定:

const speechConfig = sdk.SpeechConfig.fromHost("http://localhost:5000");

不要使用此 Azure 雲端初始化設定:

SPXSpeechConfiguration *speechConfig = [[SPXSpeechConfiguration alloc] initWithSubscription:...];

搭配容器主機使用此設定:

SPXSpeechConfiguration *speechConfig = [[SPXSpeechConfiguration alloc] initWithHost:"http://localhost:5000"];

不要使用此 Azure 雲端初始化設定:

let speechConfig = SPXSpeechConfiguration(subscription: "", region: "");

搭配容器主機使用此設定:

let speechConfig = SPXSpeechConfiguration(host: "http://localhost:5000");

不要使用此 Azure 雲端初始化設定:

speech_config = speechsdk.SpeechConfig(
    subscription=speech_key, region=service_region)

搭配容器端點使用此設定:

speech_config = speechsdk.SpeechConfig(
    host="http://localhost:5000")

當您在容器中使用語音 CLI 時,請包含 --host http://localhost:5000/ 選項。 您也必須指定 --key none 來確保 CLI 不會嘗試使用語音金鑰進行驗證。 如需如何設定語音 CLI 的詳細資訊,請參閱開始使用 Azure AI 語音 CLI

嘗試使用主機驗證來識別語言 ,而不是密鑰和區域。 當您在容器中執行語言識別碼時,請使用 SourceLanguageRecognizer 物件,而不是 SpeechRecognizerTranslationRecognizer

下一步