From f87876e5885c65d25c3b1c4127efb547a165e4a1 Mon Sep 17 00:00:00 2001 From: ProgramComputer <22284856+ProgramComputer@users.noreply.github.com> Date: Sun, 31 Dec 2023 19:35:44 +0000 Subject: [PATCH] calls speech synthesis if async not finished --- edit_languages.php | 8 ++++++-- js/pgm.js | 3 ++- src/js/user_interactions.js | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/edit_languages.php b/edit_languages.php index d34a16ea..c4567afe 100644 --- a/edit_languages.php +++ b/edit_languages.php @@ -691,8 +691,12 @@ function (translation) { LWT_DATA.language.ttsVoiceApi = api_value; const text = document.forms.lg_form.LgVoiceAPIDemo.value; const lang = ; - readTextAloud(text, lang); - LWT_DATA.language.ttsVoiceApi = prevApi; + + if( readTextAloud(text, lang)) + { + LWT_DATA.language.ttsVoiceApi = prevApi; + } + }, fullFormCheck: function () { diff --git a/js/pgm.js b/js/pgm.js index 985903ae..43200365 100644 --- a/js/pgm.js +++ b/js/pgm.js @@ -477,4 +477,5 @@ if(rate){msg.rate=rate}else if(getCookie(prefix+'Rate]')){msg.rate=parseInt(getC if(pitch){msg.pitch=pitch}else if(getCookie(prefix+'Pitch]')){msg.pitch=parseInt(getCookie(prefix+'Pitch]'),10)} if(LWT_DATA.language.ttsVoiceApi){readTextWithExternalApp(text,lang)}else{window.speechSynthesis.speak(msg)} return msg} -function readTextAloud(text,lang,rate,pitch,voice){if(lang.startsWith('ja')){getPhoneticTextAsync(text,lang).then(function(data){readRawTextAloud(data.phonetic_reading,lang,rate,pitch,voice)})}else{readRawTextAloud(text,lang,rate,pitch,voice)}} \ No newline at end of file +function readTextAloud(text,lang,rate,pitch,voice){if(lang.startsWith('ja')){getPhoneticTextAsync(text,lang).then(function(data){readRawTextAloud(data.phonetic_reading,lang,rate,pitch,voice);return!0})}else{readRawTextAloud(text,lang,rate,pitch,voice);return!0} +return!1} \ No newline at end of file diff --git a/src/js/user_interactions.js b/src/js/user_interactions.js index be702c19..1c8a502c 100644 --- a/src/js/user_interactions.js +++ b/src/js/user_interactions.js @@ -340,9 +340,12 @@ function readTextAloud(text, lang, rate, pitch, voice) { readRawTextAloud( data.phonetic_reading, lang, rate, pitch, voice ); + return true; } ); } else { readRawTextAloud(text, lang, rate, pitch, voice); + return true; } + return false; }