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

Ignore speech synthesis errors #2300

Merged
merged 5 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix [#1515](https://github.com/microsoft/BotFramework-WebChat/issues/1515). Added dynamic phrases when using Cognitive Services Speech Services, by [@compulim](https://github.com/compulim) in PR [#2246](https://github.com/microsoft/BotFramework-WebChat/pull/2246)
- Fix [#2273](https://github.com/microsoft/BotFramework-WebChat/issues/2273). Add `ScreenReaderText` component, by [@corinagum](https://github.com/corinagum) in PR [#2278](https://github.com/microsoft/BotFramework-WebChat/pull/2278)
- Fix [#2231](https://github.com/microsoft/BotFramework-WebChat/issues/2231). Fallback to English (US) if date time formatting failed, by [@compulim](https://github.com/compulim) in PR [#2286](https://github.com/microsoft/BotFramework-WebChat/pull/2286)
- Fix [#2298](https://github.com/microsoft/BotFramework-WebChat/issues/2298). Speech synthesize errors to be ignored, by [@compulim](https://github.com/compulim) in PR [#2300](https://github.com/microsoft/BotFramework-WebChat/issues/2300)

### Added

Expand Down
12 changes: 6 additions & 6 deletions __tests__/inputHint.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('input hint', () => {

await driver.wait(uiConnected(), timeouts.directLine);

await pageObjects.sendMessageViaMicrophone('hint expecting input');
await pageObjects.sendMessageViaMicrophone('hint expecting');

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

Expand All @@ -41,7 +41,7 @@ describe('input hint', () => {

await driver.wait(uiConnected(), timeouts.directLine);

await pageObjects.sendMessageViaMicrophone('hint expecting input');
await pageObjects.sendMessageViaMicrophone('hint expecting');

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

Expand All @@ -59,7 +59,7 @@ describe('input hint', () => {

await driver.wait(uiConnected(), timeouts.directLine);

await pageObjects.sendMessageViaMicrophone('hint accepting input');
await pageObjects.sendMessageViaMicrophone('hint accepting');

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

Expand All @@ -79,7 +79,7 @@ describe('input hint', () => {

await driver.wait(uiConnected(), timeouts.directLine);

await pageObjects.sendMessageViaSendBox('hint accepting input');
await pageObjects.sendMessageViaSendBox('hint accepting');

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

Expand All @@ -97,7 +97,7 @@ describe('input hint', () => {

await driver.wait(uiConnected(), timeouts.directLine);

await pageObjects.sendMessageViaMicrophone('hint ignoring input');
await pageObjects.sendMessageViaMicrophone('hint ignoring');

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

Expand All @@ -117,7 +117,7 @@ describe('input hint', () => {

await driver.wait(uiConnected(), timeouts.directLine);

await pageObjects.sendMessageViaSendBox('hint ignoring input');
await pageObjects.sendMessageViaSendBox('hint ignoring');

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);

Expand Down
5 changes: 5 additions & 0 deletions __tests__/setup/pageObjects/errorSpeechSynthesize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import executePromiseScript from './executePromiseScript';

export default async function errorSpeechSynthesize(driver, reason) {
return await executePromiseScript(driver, reason => window.WebSpeechMock.mockErrorSynthesize(reason), reason);
}
2 changes: 2 additions & 0 deletions __tests__/setup/pageObjects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import clickSendButton from './clickSendButton';
import clickSuggestedActionButton from './clickSuggestedActionButton';
import dispatchAction from './dispatchAction';
import endSpeechSynthesize from './endSpeechSynthesize';
import errorSpeechSynthesize from './errorSpeechSynthesize';
import executePromiseScript from './executePromiseScript';
import getNumActivitiesShown from './getNumActivitiesShown';
import getSendBoxText from './getSendBoxText';
Expand Down Expand Up @@ -32,6 +33,7 @@ export default function pageObjects(driver) {
clickSuggestedActionButton,
dispatchAction,
endSpeechSynthesize,
errorSpeechSynthesize,
executePromiseScript,
getNumActivitiesShown,
getSendBoxText,
Expand Down
12 changes: 12 additions & 0 deletions __tests__/setup/web/mockWebSpeech.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ window.WebSpeechMock = {
});
},

mockErrorSynthesize(error = 'artificial-error') {
return new Promise(resolve => {
speechSynthesisBroker.consume(utterance => {
utterance.dispatchEvent({ error, type: 'error' });

const { lang, pitch, rate, text, voice, volume } = utterance;

resolve({ lang, pitch, rate, text, voice, volume });
});
});
},

mockRecognize(...args) {
speechRecognitionBroker.produce(...args);
},
Expand Down
2 changes: 1 addition & 1 deletion __tests__/speech.recognition.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('speech recognition', () => {
}
});

await pageObjects.sendMessageViaMicrophone('hint expecting input');
await pageObjects.sendMessageViaMicrophone('hint expecting');

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);
Expand Down
20 changes: 20 additions & 0 deletions __tests__/speech.synthesis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { timeouts } from './constants.json';

import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import speechRecognitionStartCalled from './setup/conditions/speechRecognitionStartCalled';
import speechSynthesisUtterancePended from './setup/conditions/speechSynthesisUtterancePended';

// selenium-webdriver API doc:
Expand Down Expand Up @@ -54,4 +55,23 @@ describe('speech synthesis', () => {

await pageObjects.endSpeechSynthesize();
});

test('should start recognition after failing on speech synthesis with activity of expecting input', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
webSpeechPonyfillFactory: () => window.WebSpeechMock
}
});

await pageObjects.sendMessageViaMicrophone('hint expecting');

await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeFalsy();
await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(speechSynthesisUtterancePended(), timeouts.ui);

await pageObjects.startSpeechSynthesize();
await pageObjects.errorSpeechSynthesize();

await expect(speechRecognitionStartCalled().fn(driver)).resolves.toBeTruthy();
});
});
6 changes: 3 additions & 3 deletions packages/bundle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"prop-types": "^15.7.2",
"sanitize-html": "^1.19.0",
"url-search-params-polyfill": "^5.0.0",
"web-speech-cognitive-services": "4.0.1-master.ad6e780",
"web-speech-cognitive-services": "4.0.1-master.d9fc5d3",
"whatwg-fetch": "^3.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/component/src/Activity/Speak.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Speak = ({ activity, markAsSpoken, selectVoice, styleSet }) => {

return (
<React.Fragment>
<Say onEnd={markAsSpoken} speak={singleLine} voice={selectVoice} />
<Say onEnd={markAsSpoken} onError={markAsSpoken} speak={singleLine} voice={selectVoice} />
{!!styleSet.options.showSpokenText && <SayAlt speak={singleLine} voice={selectVoice} />}
</React.Fragment>
);
Expand Down