Skip to content

Commit

Permalink
Converted voices to voicesProperty, improve NumberSuiteCommonSpeechSy…
Browse files Browse the repository at this point in the history
…nthesisAnnouncer, see phetsims/utterance-queue#96
  • Loading branch information
chrisklus committed Dec 1, 2022
1 parent ba64751 commit d5e4ed5
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions js/preferences/VoicingPanelSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ class VoicingPanelSection extends PreferencesPanelSection {
audioModel.voicingEnabledProperty.lazyLink( voicingEnabledPropertyListener );

// when the list of voices for the ComboBox changes, create a new ComboBox that includes the supported
// voices
// voices. Eagerly create the first ComboBox, even if no voices are available.
let voiceComboBox: VoiceComboBox | null = null;
const voicesChangedListener = () => {
const voicesChangedListener = ( voices: SpeechSynthesisVoice[] ) => {
if ( voiceComboBox ) {
voiceOptionsContent.removeChild( voiceComboBox );
voiceComboBox.dispose();
Expand All @@ -322,11 +322,11 @@ class VoicingPanelSection extends PreferencesPanelSection {
let voiceList: SpeechSynthesisVoice[] = [];

// Only get the prioritized and pruned list of voices if the VoicingManager has voices
// available, otherwise wait until the next voicesChangedEmitter message. If there are no voices
// available VoiceComboBox will handle that gracefully.
// available, otherwise wait until they are available. If there are no voices available VoiceComboBox will handle
// that gracefully.
// Voice changing is not (as of this writing) available on MacOS or iOS, but we hope they fix that bug soon. Perhaps
// next time someone is working in this area, they can check and see if it is working, https://github.com/phetsims/utterance-queue/issues/74
if ( voicingManager.voices.length > 0 ) {
if ( voices.length > 0 ) {
const prioritizedVoices = voicingManager.getPrioritizedVoices();

// for now, only english voices are available because the Voicing feature is not translatable
Expand All @@ -346,10 +346,7 @@ class VoicingPanelSection extends PreferencesPanelSection {
voiceComboBox = new VoiceComboBox( audioModel.voiceProperty, voiceList, parent );
voiceOptionsContent.addChild( voiceComboBox );
};
voicingManager.voicesChangedEmitter.addListener( voicesChangedListener );

// eagerly create the first ComboBox, even if no voices are available
voicesChangedListener();
voicingManager.voicesProperty.link( voicesChangedListener );

voiceOptionsOpenProperty.lazyLink( open => {
const alertStringProperty = open ? customizeVoiceExpandedStringProperty : customizeVoiceCollapsedStringProperty;
Expand All @@ -368,7 +365,7 @@ class VoicingPanelSection extends PreferencesPanelSection {
rateSlider.dispose();
audioModel.voicingEnabledProperty.unlink( voicingEnabledPropertyListener );
audioModel.voicingEnabledProperty.unlink( contentVisibilityListener );
voicingManager.voicesChangedEmitter.removeListener( voicesChangedListener );
voicingManager.voicesProperty.unlink( voicesChangedListener );
localeProperty.unlink( localeListener );
voicingEnabledSwitch.dispose();
voiceOptionsOpenProperty.dispose();
Expand Down

0 comments on commit d5e4ed5

Please sign in to comment.