You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已使用全球MS Azure Cognitive Services SDK的Web应用切换中国区Speech-to-Text的技术咨询

Hey there! Let's walk through everything you need to know to switch your JavaScript Speech-to-Text setup from global Azure to Azure China, plus how to integrate both regions seamlessly in your web app. I've broken this down into clear, actionable sections below:

Key Differences Between Azure Global and Azure China for Speech Services

First, let's cover the core distinctions that matter for your implementation:

  • Data Residency & Compliance: Azure China operates as an independent instance, with all data stored within China's borders and subject to local regulations (like the Cybersecurity Law of China). This doesn't change how Speech-to-Text works, but you'll need to ensure your use case aligns with these rules.
  • Service Endpoints: This is the biggest technical gap—Azure China uses entirely separate endpoints from global Azure; there's no cross-region compatibility here.
  • Authentication Credentials: Azure China subscription keys or Azure AD credentials won't work with global Azure (and vice versa). You'll need to use credentials specifically generated for your Azure China Speech resource.
WebSocket Connection Differences for Speech-to-Text

For Speech-to-Text over WebSocket, the endpoint structure is different between the two environments:

  • Global Azure typically uses endpoints like wss://<region>.stt.speech.microsoft.com/speech/universal/v2
  • Azure China uses a modified base domain, following this format:
    wss://<region>.stt.speech.azure.cn/speech/universal/v2
    

Valid region codes for Azure China Speech Services are:

  • chinaeast2
  • chinanorth
  • chinanorth2

When setting up the WebSocket connection, remember to:

  1. Use the endpoint that matches your Azure China Speech resource's region
  2. Pass your Azure China subscription key (or a token generated from it) in the Authorization header—same auth pattern as global, but with China-specific credentials
SDK Support for Azure China

Good news: You don't need a separate "China-only" JavaScript SDK. The official Microsoft Cognitive Services Speech SDK works for both regions—you just need to explicitly configure it to target Azure China's endpoints.

Here's a quick example of initializing the SDK for Azure China:

import { SpeechConfig, AudioConfig, SpeechRecognizer, ResultReason } from 'microsoft-cognitiveservices-speech-sdk';

// Initialize with your Azure China key and region
const speechConfig = SpeechConfig.fromSubscription('YOUR_AZURE_CHINA_SUBSCRIPTION_KEY', 'chinaeast2');
// Override the endpoint to point to Azure China's Speech Service
speechConfig.setServiceProperty('SpeechServiceConnectionEndpoint', 'wss://chinaeast2.stt.speech.azure.cn/speech/universal/v2');

// Rest of your code stays nearly identical to global setup
const audioConfig = AudioConfig.fromDefaultMicrophoneInput();
const recognizer = new SpeechRecognizer(speechConfig, audioConfig);

recognizer.recognized = (s, e) => {
    if (e.result.reason === ResultReason.RecognizedSpeech) {
        console.log(`China Region Recognized Text: ${e.result.text}`);
    }
};

recognizer.startContinuousRecognitionAsync();
Integrating Both Global and Azure China in Your Web App

To support both regions in a single app, create a helper function that handles region-specific configuration:

function createSpeechConfig(region, subscriptionKey, isChinaRegion = false) {
    const speechConfig = SpeechConfig.fromSubscription(subscriptionKey, region);
    
    if (isChinaRegion) {
        // Set China-specific endpoint
        const chinaEndpoint = `wss://${region}.stt.speech.azure.cn/speech/universal/v2`;
        speechConfig.setServiceProperty('SpeechServiceConnectionEndpoint', chinaEndpoint);
    }
    
    return speechConfig;
}

// Usage for Global Azure
const globalSpeechConfig = createSpeechConfig('eastus', 'YOUR_GLOBAL_SUBSCRIPTION_KEY');
// Usage for Azure China
const chinaSpeechConfig = createSpeechConfig('chinaeast2', 'YOUR_CHINA_SUBSCRIPTION_KEY', true);
Additional Tips
  • Token Authentication: If you prefer token-based auth over direct subscription keys, generate tokens using Azure China's token endpoint: https://<region>.api.azure.cn/sts/v1.0/issueToken (instead of the global https://<region>.api.cognitive.microsoft.com/sts/v1.0/issueToken).
  • Network Testing: If you're testing from outside China, you might encounter network restrictions—try testing from a China-based environment if possible to validate connectivity.
  • Feature Parity: Most core Speech-to-Text features are identical between global and China regions, but always verify any niche features you use against Azure China's service documentation.

内容的提问来源于stack exchange,提问作者Анастасия Яцура

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:16:46