Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOs speech recognition does not work with an input hint of expecting input #1028

Closed
rosskyl opened this issue Jun 27, 2018 · 1 comment
Closed
Labels
Duplicate This issue or pull request already exists

Comments

@rosskyl
Copy link
Contributor

rosskyl commented Jun 27, 2018

I am using the direct line with the code below. I have speech recognition working with IOs but when a response with the input hint set to expecting input comes back, speech recognition becomes unusable until I send something back. This often happens with PromptDialog.Confirm. Since IOs does not allow audio recording unless done from a direct user tap/click, I am guessing the problem is with the speech recognizer trying to start recording audio but it can't.

const user = {
    id: document.getElementById("userId").value,
    name: document.getElementById("userName").value
};

const bot = {
    id: params['botid'] || 'botid',
    name: params['botname'] || 'botname'
};

window.botchatDebug = params['debug'] && params['debug'] === 'true';

var speechOptions;
if (Modernizr.speechsynthesis) {
    speechOptions = {
        speechRecognizer: new CognitiveServices.SpeechRecognizer({
            fetchCallback: (authFetchEventId) => getBingToken(),
            fetchOnExpiryCallback: (authFetchEventId) => getBingToken()
        }),
        speechSynthesizer: new BotChat.Speech.BrowserSpeechSynthesizer()
    };
}
else {
    speechOptions = null;
}

var botConnection = new BotChat.DirectLine({
    domain: params['domain'],
    token: document.getElementById("directLineToken").value, 
    webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
});

BotChat.App({
    bot: bot,
    locale: params['locale'],
    resize: 'detect',
    speechOptions: speechOptions,
    user: user,
    botConnection: botConnection
}, document.getElementById('BotChatGoesHere'));

var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

function SpeakText() {
    var msg = new SpeechSynthesisUtterance();
    window.speechSynthesis.speak(msg);

    document.getElementsByClassName("wc-mic")[0].removeEventListener("click", SpeakText);
}

if (isSafari) {

    window.addEventListener("load", function () {
        document.getElementsByClassName("wc-mic")[0].addEventListener("click", SpeakText);
    });
}

// Needed to change between the two audio contexts
var AudioContext = window.AudioContext || window.webkitAudioContext;

// Sets the old style getUserMedia to use the new style that is supported in more browsers even though the framework uses the new style
window.navigator.getUserMedia = function (constraints, successCallback, errorCallback) {
    window.navigator.mediaDevices.getUserMedia(constraints)
        .then(function (e) {
            successCallback(e);
        })
        .catch(function (e) {
            errorCallback(e);
        });
};
@corinagum corinagum added the Duplicate This issue or pull request already exists label Nov 29, 2018
@corinagum
Copy link
Contributor

This issue is being tracked on #1328. :)

@microsoft microsoft locked and limited conversation to collaborators Sep 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants