Skip to content

Commit

Permalink
Merge pull request #1591 from RodriSanchez1/fix/downloadTts
Browse files Browse the repository at this point in the history
Fix / Download tts
  • Loading branch information
martinbedouret authored Oct 30, 2023
2 parents 72db0f3 + 957426c commit 09de33d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/components/Settings/Language/Language.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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(
<FormattedMessage {...messages.instaledLangSuccesNotification} />
);
Expand Down
5 changes: 3 additions & 2 deletions src/providers/LanguageProvider/LanguageProvider.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/providers/SpeechProvider/SpeechProvider.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions src/providers/SpeechProvider/tts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
}
},
Expand All @@ -180,7 +183,7 @@ const tts = {
if (!isAndroid()) {
return;
} else {
const ttsDefaultEng = synth.getDefaultEngine();
const ttsDefaultEng = synth.getDefaultEngine() || {};
return ttsDefaultEng;
}
},
Expand Down

0 comments on commit 09de33d

Please sign in to comment.