Skip to content

Commit 36432e9

Browse files
committed
revise previous to use a separate langs attribute instead
1 parent a854741 commit 36432e9

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

js/defaults.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ function groupVoicesByLang(voices) {
196196
}
197197

198198
function getVoiceLanguages(voice) {
199-
return voice.lang
200-
? (Array.isArray(voice.lang) ? voice.lang : [voice.lang])
201-
: null
199+
if (voice.langs) return voice.langs
200+
else if (voice.lang) return [voice.lang]
201+
else return undefined
202202
}
203203

204204
function getFirstLanguage(voice) {
205-
if (Array.isArray(voice.lang)) return voice.lang[0]
205+
if (voice.langs) return voice.langs[0]
206206
else return voice.lang
207207
}
208208

js/tts-engines.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,10 @@ function AmazonPollyTtsEngine() {
516516
if (voice.Style) voiceName += ` +${voice.Style}`;
517517
return {
518518
voiceName,
519-
lang: voice.AdditionalLanguageCodes
519+
lang: voice.LanguageCode,
520+
langs: voice.AdditionalLanguageCodes
520521
? [voice.LanguageCode, ...voice.AdditionalLanguageCodes]
521-
: voice.LanguageCode,
522+
: undefined,
522523
gender: voice.Gender.toLowerCase(),
523524
}
524525
})
@@ -959,15 +960,15 @@ function PhoneTtsEngine() {
959960
function OpenaiTtsEngine() {
960961
this.defaultEndpointUrl = "https://api.openai.com/v1"
961962
this.defaultVoiceList = [
962-
{voice: "alloy", lang: ["en-US", "zh-CN"], model: "tts-1"},
963-
{voice: "ash", lang: ["en-US", "zh-CN"], model: "tts-1"},
964-
{voice: "coral", lang: ["en-US", "zh-CN"], model: "tts-1"},
965-
{voice: "echo", lang: ["en-US", "zh-CN"], model: "tts-1"},
966-
{voice: "fable", lang: ["en-US", "zh-CN"], model: "tts-1"},
967-
{voice: "onyx", lang: ["en-US", "zh-CN"], model: "tts-1"},
968-
{voice: "nova", lang: ["en-US", "zh-CN"], model: "tts-1"},
969-
{voice: "sage", lang: ["en-US", "zh-CN"], model: "tts-1"},
970-
{voice: "shimmer", lang: ["en-US", "zh-CN"], model: "tts-1"},
963+
{voice: "alloy", langs: ["en-US", "zh-CN"], model: "tts-1"},
964+
{voice: "ash", langs: ["en-US", "zh-CN"], model: "tts-1"},
965+
{voice: "coral", langs: ["en-US", "zh-CN"], model: "tts-1"},
966+
{voice: "echo", langs: ["en-US", "zh-CN"], model: "tts-1"},
967+
{voice: "fable", langs: ["en-US", "zh-CN"], model: "tts-1"},
968+
{voice: "onyx", langs: ["en-US", "zh-CN"], model: "tts-1"},
969+
{voice: "nova", langs: ["en-US", "zh-CN"], model: "tts-1"},
970+
{voice: "sage", langs: ["en-US", "zh-CN"], model: "tts-1"},
971+
{voice: "shimmer", langs: ["en-US", "zh-CN"], model: "tts-1"},
971972
]
972973
var prefetchAudio
973974
this.test = async function({apiKey, url, voiceList}) {
@@ -999,9 +1000,10 @@ function OpenaiTtsEngine() {
9991000
this.getVoices = async function() {
10001001
const openaiCreds = await getSetting("openaiCreds")
10011002
const voiceList = openaiCreds ? (openaiCreds.voiceList || this.defaultVoiceList) : []
1002-
return voiceList.map(({voice, lang}) => ({
1003+
return voiceList.map(({voice, lang, langs}) => ({
10031004
voiceName: "OpenAI " + voice,
1004-
lang
1005+
lang,
1006+
langs
10051007
}))
10061008
}
10071009
async function getAudioUrl(text, voice, pitch) {

0 commit comments

Comments
 (0)