Skip to content

Commit

Permalink
example of speaking full response, see #381
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed May 17, 2021
1 parent e790141 commit aa510d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
16 changes: 16 additions & 0 deletions js/common/view/describers/RatioDescriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ class RatioDescriber {
} );
}

/**
* Get a description fragment describing the antecedent value to the consequent value,
* something like:
* "1 to 2"
* @public
*
* @param {number} antecedent
* @param {number} consequent
*/
getAntecedentToConsequentFragnemt( antecedent, consequent ) {
return StringUtils.fillIn( ratioAndProportionStrings.a11y.ratio.antecedentToConsequentPattern, {
targetAntecedent: antecedent,
targetConsequent: consequent
} );
}

/**
* @public
* @param {number} antecedent
Expand Down
17 changes: 9 additions & 8 deletions js/create/view/MyChallengeAccordionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,34 @@ class MyChallengeAccordionBox extends AccordionBox {

const accordionBoxUtterance = new ActivationUtterance();
const accordionBoxVoicingUtterance = new ActivationUtterance();
this.expandedProperty.lazyLink( expanded => {
this.expandedProperty.link( ( expanded, oldValue ) => {

// strings containing responses used for Voicing
let contextResponse = '';
let objectResponse = '';
let hintResponse = '';

if ( expanded ) {
contextResponse = ratioDescriber.getCurrentChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value );
objectResponse = ratioDescriber.getAntecedentToConsequentFragnemt( targetAntecedentProperty.value, targetConsequentProperty.value );
hintResponse = ratioAndProportionStrings.a11y.create.myChallengeExpandedHintText;

accordionBoxUtterance.alert = ratioDescriber.getCurrentChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value );
}
else {
contextResponse = ratioAndProportionStrings.a11y.ratio.currentChallengeHidden;
objectResponse = ratioAndProportionStrings.a11y.ratio.hidden;
hintResponse = ratioAndProportionStrings.a11y.create.myChallengeCollapsedHintText;

accordionBoxUtterance.alert = ratioAndProportionStrings.a11y.ratio.currentChallengeHidden;
}

this.setButtonVoicingOptions( {
voicingContextResponse: contextResponse,
voicingObjectResponse: objectResponse,
voicingHintResponse: hintResponse
} );

this.voicingSpeakButtonResponse( { utterance: accordionBoxVoicingUtterance } );
phet.joist.sim.utteranceQueue.addToBack( accordionBoxUtterance );

if ( oldValue !== null ) {
this.voicingSpeakButtonResponse( { utterance: accordionBoxVoicingUtterance } );
phet.joist.sim.utteranceQueue.addToBack( accordionBoxUtterance );
}
} );

Property.multilink( [ targetAntecedentProperty, targetConsequentProperty ], ( targetAntecedent, targetConsequent ) => {
Expand Down
6 changes: 6 additions & 0 deletions ratio-and-proportion-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,15 @@
"myChallenge": {
"value": "My Challenge {{targetAntecedent}} to {{targetConsequent}}."
},
"antecedentToConsequentPattern": {
"value": "{{targetAntecedent}} to {{targetConsequent}}"
},
"myChallengeHidden": {
"value": "My Challenge hidden."
},
"hidden": {
"value": "hidden"
},
"capitalized": {
"at": {
"value": "At"
Expand Down

0 comments on commit aa510d8

Please sign in to comment.