Skip to content

Commit

Permalink
Cleans up code, closes #182.
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoFara committed Jan 5, 2024
1 parent 261e7a8 commit 4d6b109
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
3 changes: 2 additions & 1 deletion js/pgm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 36 additions & 35 deletions src/js/user_interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,43 +341,44 @@ function readTextAloud (text, lang, rate, pitch, voice, convert_to_phonetic) {
}
}

function handleReadingConfiguration(language, term, lang_id) {
if (language.reading_mode == "direct" || language.reading_mode == "internal") {
const lang_settings = cookieTTSSettings(language.name);
if (language.reading_mode == "direct") {
// No reparsing needed
readRawTextAloud(
term,
language.abbreviation,
lang_settings.rate,
lang_settings.pitch,
lang_settings.voice
);
} else {
// Server handled reparsing
getPhoneticTextAsync(term, parseInt(lang_id, 10))
.then(
function (reparsed_text) {
readRawTextAloud(
reparsed_text.phonetic_reading,
language.abbreviation,
lang_settings.rate,
lang_settings.pitch,
lang_settings.voice
);
}
);
}
} else if (language.reading_mode == "external") {
// Use external API
readTextWithExternal(term, language.voiceapi, language.name);
}

}

function speechDispatcher (term, lang_id) {
return $.getJSON(
'api.php/v1/languages/' + lang_id + '/reading-configuration',
{
lgid: lang_id
},
function (data) {
if (data.reading_mode == "direct" || data.reading_mode == "internal") {
const lang_settings = cookieTTSSettings(data.language);
if (data.reading_mode == "direct") {
// No reparsing needed
readRawTextAloud(
term,
data.abbreviation,
lang_settings.rate,
lang_settings.pitch,
lang_settings.voice
);
} else if (data.reading_mode == "internal") {
// Server handled reparsing
getPhoneticTextAsync(term, parseInt(lang_id, 10))
.then(
function (reparsed_text) {
readRawTextAloud(
reparsed_text.phonetic_reading,
data.abbreviation,
lang_settings.rate,
lang_settings.pitch,
lang_settings.voice
);
}
);
}
} else if (data.reading_mode == "external") {
// Use external API
readTextWithExternal(term, data.voiceApi, data.language);
}
}
{ lang_id },
(data) => handleReadingConfiguration(data, term, parseInt(lang_id, 10))
);
}

0 comments on commit 4d6b109

Please sign in to comment.