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

如何配置WebChat语音聊天机器人识别印地语(hi-IN)并转印地语文本?

Get Your Hindi (hi-IN) Speech Recognition Working with Azure Cognitive Speech Services

Hey there! Let's get your Web Chat bot set up to recognize Hindi speech and convert it to text using Azure Cognitive Speech Services. Right now, your code uses the browser's default Web Speech API which might not reliably support Hindi, so we'll swap that out with Azure's dedicated speech service for better accuracy and language support.

Here's how to adjust your code step by step:

1. Add the Azure Cognitive Speech SDK

First, you'll need to include the Azure Cognitive Speech Services SDK in your HTML page. You can download the latest SDK bundle from Azure's official resources and host it locally (no external links needed) to ensure it's available for your code.

2. Implement a Custom Speech Ponyfill Factory

Add this custom factory function before your existing Web Chat initialization code. This will handle speech recognition using Azure's service and target Hindi specifically:

function createCognitiveServicesSpeechPonyfillFactory(speechKey, serviceRegion) {
  return () => {
    // Configure your Azure Speech Service credentials
    const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(speechKey, serviceRegion);
    // Set Hindi as the recognition language
    speechConfig.speechRecognitionLanguage = 'hi-IN';

    const startRecognition = () => new Promise((resolve, reject) => {
      // Create a speech recognizer instance
      const recognizer = new SpeechSDK.SpeechRecognizer(speechConfig);

      // Handle successful speech recognition
      recognizer.recognized = (_, event) => {
        if (event.result.reason === SpeechSDK.ResultReason.RecognizedSpeech) {
          resolve({ transcript: event.result.text });
        } else if (event.result.reason === SpeechSDK.ResultReason.NoMatch) {
          reject(new Error('No speech could be recognized'));
        }
      };

      // Handle errors or cancellation
      recognizer.canceled = (_, event) => {
        reject(new Error(event.errorDetails || 'Recognition was canceled'));
        recognizer.stopContinuousRecognitionAsync();
      };

      // Start listening for speech input
      recognizer.startContinuousRecognitionAsync();
    });

    return {
      SpeechRecognition: class {
        start() { return startRecognition(); }
        // Optional: Add a stop method if you need to manually halt recognition
        stop() { /* Add stop logic here if required */ }
      }
    };
  };
}

3. Update Your Web Chat Configuration

In your existing window.WebChat.renderWebChat call, replace the default webSpeechPonyfillFactory with our custom one. Make sure to replace YOUR_AZURE_SPEECH_KEY and YOUR_SERVICE_REGION with your actual Azure Speech Service credentials:

window.WebChat.renderWebChat({
  directLine: window.WebChat.createDirectLine({ token }),
  // Use the custom Azure Speech ponyfill factory instead of the browser's default
  webSpeechPonyfillFactory: createCognitiveServicesSpeechPonyfillFactory('YOUR_AZURE_SPEECH_KEY', 'YOUR_SERVICE_REGION'),
  styleOptions: {
    hideUploadButton: true,
    bubbleBackground: '#cccccc',
    bubbleBorder: 'solid 1px #E6E6E6'
  },
  store
}, document.getElementById('webchat'));

4. Final Checks

  • Ensure your Azure Cognitive Speech Service resource is active and has the necessary permissions.
  • When testing, make sure you grant microphone access to the browser.
  • Speak in Hindi, and the bot should now convert your speech to accurate Hindi text for processing.

内容的提问来源于stack exchange,提问作者Annabelle79

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 16:23:15