diff --git a/src/components/Settings/Language/Language.container.js b/src/components/Settings/Language/Language.container.js index 5cfc1056b..1271c7264 100644 --- a/src/components/Settings/Language/Language.container.js +++ b/src/components/Settings/Language/Language.container.js @@ -92,10 +92,10 @@ export class LanguageContainer extends Component { downloadingLangError: { ttsError: false, langError: false } }; - handleSubmit = async (optionalLang = null) => { + handleSubmit = async (optionalLang = null, isNewVoiceAvailable = false) => { const { onLangChange } = this.props; const selectedLang = optionalLang ? optionalLang : this.state.selectedLang; - onLangChange(selectedLang); + onLangChange(selectedLang, isNewVoiceAvailable); this.initArasaacDB(selectedLang); try { await API.updateSettings({ @@ -196,17 +196,19 @@ export class LanguageContainer extends Component { onDialogAcepted = downloadingLangData => { const { marketId, lang, ttsName, continueOnline } = downloadingLangData; this.setState({ openDialog: { open: false, downloadingLangData: {} } }); - onAndroidPause(() => this.pauseCallback()); const downloadingLangState = { isdownloading: true, isDiferentTts: false, engineName: ttsName, marketId: marketId, - selectedLang: lang + selectedLang: lang, + firstClick: false, + continueOnline: false }; this.props.setDownloadingLang(downloadingLangState); if (continueOnline) this.handleSubmit(lang); window.cordova.plugins.market.open(marketId); + navigator.app.exitApp(); }; onCloseDialog = () => { @@ -462,7 +464,8 @@ export class LanguageContainer extends Component { }); this.refreshLanguageList(); if (isDiferentTts) return; - await this.handleSubmit(selectedLang); + const isNewVoiceAvailable = true; + await this.handleSubmit(selectedLang, isNewVoiceAvailable); showNotification( ); diff --git a/src/providers/LanguageProvider/LanguageProvider.actions.js b/src/providers/LanguageProvider/LanguageProvider.actions.js index 399629565..3fde75d18 100644 --- a/src/providers/LanguageProvider/LanguageProvider.actions.js +++ b/src/providers/LanguageProvider/LanguageProvider.actions.js @@ -5,11 +5,12 @@ import { } from './LanguageProvider.constants'; import { updateUserData } from '../../components/App/App.actions'; -export function changeLang(lang) { +export function changeLang(lang, isNewVoiceAvailable = false) { updateUserData(); return { type: CHANGE_LANG, - lang + lang, + isNewVoiceAvailable }; } diff --git a/src/providers/SpeechProvider/SpeechProvider.reducer.js b/src/providers/SpeechProvider/SpeechProvider.reducer.js index 840621fe5..6f7fd5337 100644 --- a/src/providers/SpeechProvider/SpeechProvider.reducer.js +++ b/src/providers/SpeechProvider/SpeechProvider.reducer.js @@ -124,7 +124,8 @@ function speechProviderReducer(state = initialState, action) { options: { ...state.options, voiceURI: - state.options.lang.substring(0, 2) !== action.lang.substring(0, 2) + state.options.lang.substring(0, 2) !== + action.lang.substring(0, 2) || action.isNewVoiceAvailable ? getVoiceURI(action.lang, state.voices) : state.options.voiceURI, lang: diff --git a/src/providers/SpeechProvider/tts.js b/src/providers/SpeechProvider/tts.js index 3568e48ad..bf9c11ec7 100644 --- a/src/providers/SpeechProvider/tts.js +++ b/src/providers/SpeechProvider/tts.js @@ -171,7 +171,10 @@ const tts = { if (!isAndroid()) { return []; } else { - const ttsEngs = synth.getEngines(); + if (synth === undefined) { + synth = window.speechSynthesis; + } + const ttsEngs = synth.getEngines() || {}; return ttsEngs._list || []; } }, @@ -180,7 +183,7 @@ const tts = { if (!isAndroid()) { return; } else { - const ttsDefaultEng = synth.getDefaultEngine(); + const ttsDefaultEng = synth.getDefaultEngine() || {}; return ttsDefaultEng; } },