Ejemplo n.º 1
0
        // Simply say what is to be said
        public async Task SpeakWithDelay(string prompt)
        {
            if (this.isUsingSpeech)
            {
                int msRemainingDelay = await TextToSpeechServiceHelper.SpeakTextAsync(prompt);

                await Task.Delay(msRemainingDelay);
            }
        }
Ejemplo n.º 2
0
        // Start speaking, but stop if nobody is in front of camera
        public async Task SpeakWhileCheckingPresence(string prompt)
        {
            if (this.isUsingSpeech)
            {
                int msTimeToSpeak = await TextToSpeechServiceHelper.SpeakTextAsync(prompt);

                DateTime startSpeakTime = DateTime.Now;
                DateTime endSpeakTime   = startSpeakTime.AddMilliseconds(msTimeToSpeak);
                while (DateTime.Now < endSpeakTime && this.isEngagingCustomer)
                {
                    if (await SendOffIfNoFace())
                    {
                        break;
                    }

                    await Task.Delay(500); // we can be lax with timeout here, since we are not listening
                }
            }
        }
Ejemplo n.º 3
0
        // Verify that no face is in front of camera, cancel current speaking and speak send-off message if allowed
        public async Task <bool> SendOffIfNoFace()
        {
            bool doSendOff = true;

            // Verify that there is indeed no face there (we do not want to be too sensitive when customer looks away)
            for (int i = 0; i < 20; i++)
            {
                if (this.cameraControl.NumFacesOnLastFrame != 0)
                {
                    doSendOff = false;
                    break;
                }
                await Task.Delay(300);  // TODO: tune this up for optimal customer experience
            }

            // Send off the customer
            if (doSendOff)
            {
                if (this.isUsingSpeech)
                {
                    await TextToSpeechServiceHelper.SpeakTextAsync("");

                    await Task.Delay(1000);
                }
                if (this.allowSendingOffMsg)
                {
                    this.allowSendingOffMsg = false; // DRY
                    if (this.isUsingSpeech)
                    {
                        await TextToSpeechServiceHelper.SpeakTextAsync(this.sendoffMessage);
                    }
                }
            }

            return(doSendOff);
        }