Search code examples
c#botframeworkspeech-recognitiondirect-line-botframeworkweb-chat

How to make bot understand that I'm talking hindi in webchat speech


I'm trying to build a hindi(hi-IN) voice chatbot..the bot is working in english in webchat but can anyone help me how to make the bot understand that I'm speaking hindi and it is later converted to hindi text using cognitive speech service

 <script>
        (async function () {
            const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
                method: 'POST',
                headers: new Headers({
                    'Authorization': 'Bearer 5********'
                })
            });
            const { token } = await res.json();

            const store = window.WebChat.createStore(
                {},
                ({ dispatch }) => next => action => {
                    if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
                        dispatch({
                            type: 'WEB_CHAT/SEND_EVENT',
                            payload: {
                                name: 'webchat/join',
                                value: { username: "UserName" }
                            }
                        });
                    }
                    return next(action);
                }
            );

            window.WebChat.renderWebChat({
                directLine: window.WebChat.createDirectLine({ token }),
                webSpeechPonyfillFactory: window.WebChat.createBrowserWebSpeechPonyfillFactory(),
                styleOptions: {
                    hideUploadButton: true,
                    bubbleBackground: '#cccccc',
                    bubbleBorder: 'solid 1px #E6E6E6'
                },
                store
            }, document.getElementById('webchat'));

            document.querySelector('#webchat > *').focus();
        })().catch(err => console.error(err));</script>
    ```

Solution

  • I am not quite sure I understand your question correctly but did you try something simple like this:

    ...
    const chatLocale = window.navigator.language;
    ...
    window.WebChat.renderWebChat({
        directLine: directline,
        locale: chatLocale,
        store,
        styleOptions: {
    ...
    

    You might also want to pass chatLocale in your webchat/join event.