fix: properly handle CN_043 voice in EN and KR

This commit is contained in:
Haoyu Xu
2025-11-16 12:58:37 +08:00
parent 14509596a1
commit ea0bd20211
3 changed files with 66 additions and 64 deletions

View File

@@ -95,7 +95,7 @@ export default class Voice {
this.#default.language.voice = this.#voice.languages[0]
this.#config.language = this.#default.language.voice
this.#voice.locations = this.#getVoiceLocations()
this.#voice.list = Object.keys(this.#getVoices())
this.#voice.list = this.#charwordTable.availability[this.#config.language]
}
success() {
@@ -251,15 +251,7 @@ export default class Voice {
#nextVoice() {
const getVoiceId = () => {
let list = this.#voice.list
if (
this.#config.language === 'EN' ||
this.#config.language === 'KR'
) {
// filter out CN_043 as this voice is not available in en and kr
list = list.filter((item) => item !== 'CN_043')
}
const id = list[Math.floor(Math.random() * list.length)]
const id = this.#voice.list[Math.floor(Math.random() * this.#voice.list.length)]
return id === this.#voice.id.last ? getVoiceId() : id
}
this.#playVoice(getVoiceId())
@@ -360,8 +352,10 @@ export default class Voice {
set language(lang) {
if (this.#voice.languages.includes(lang)) {
this.#config.language = lang
this.#voice.list = this.#charwordTable.availability[lang]
} else {
this.#config.language = this.#default.language.voice
this.#voice.list = this.#charwordTable.availability[this.#config.language]
}
const availableSubtitleLang = this.#getSubtitleLanguages()
if (!availableSubtitleLang.includes(this.#config.subtitle.language)) {

View File

@@ -89,6 +89,7 @@ export const build = async (namesToBuild: string[]) => {
const voiceJson = {} as OperatorCharwordTable
voiceJson.voiceLangs = {}
voiceJson.subtitleLangs = {}
voiceJson.availability = {}
const subtitleInfo = Object.keys(charwordTableLookup.info) as Region[]
const voiceList = {} as {
[key: string]: string[]
@@ -119,14 +120,8 @@ export const build = async (namesToBuild: string[]) => {
)
}
})
let voiceLangs = [] as string[]
try {
voiceLangs = getLangs(name, voiceJson).voiceLangs
file.writeSync(JSON.stringify(voiceJson), getDistDir(name))
} catch (e) {
console.log(`charword_table is not available`, e)
}
const voiceLangs = getLangs(name, voiceJson).voiceLangs
// check whether voice files has been added
const customVoiceName = voiceLangs.filter(
@@ -155,7 +150,11 @@ export const build = async (namesToBuild: string[]) => {
voiceSubFolderMapping.name
)
const voiceFileList = file.readdirSync(voiceSubFolder)
voiceList[voiceSubFolderMapping.lookup_region].map((item) => {
voiceJson.availability[voiceSubFolderMapping.lang] =
voiceFileList.map((item) => item.replace('.ogg', ''))
voiceJson.availability[voiceSubFolderMapping.lang].sort()
voiceList[voiceSubFolderMapping.lookup_region].forEach(
(item) => {
// an exception for detecting file existence
if (
item.endsWith('043') &&
@@ -176,7 +175,13 @@ export const build = async (namesToBuild: string[]) => {
`Voice folder ${voiceSubFolderMapping.name} for ${name} is missing ${item}.ogg`
)
}
})
}
)
}
file.writeSync(JSON.stringify(voiceJson), getDistDir(name))
} catch (e) {
console.log(`charword_table is not available`, e)
}
}

View File

@@ -90,6 +90,9 @@ export type CharwordTableJson = {
}
export type OperatorCharwordTable = {
availability: {
[languageCode: string]: string[]
}
voiceLangs: {
[languageCode: string]: {
[voiceLangType: string]: string[]