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

@@ -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,65 +120,69 @@ export const build = async (namesToBuild: string[]) => {
)
}
})
let voiceLangs = [] as string[]
try {
voiceLangs = getLangs(name, voiceJson).voiceLangs
const voiceLangs = getLangs(name, voiceJson).voiceLangs
// check whether voice files has been added
const customVoiceName = voiceLangs.filter(
(i) => !config.dir_name.voice.sub.map((e) => e.lang).includes(i)
)[0]
const voiceLangMapping = config.dir_name.voice.sub
.filter((e) => {
return (
voiceLangs.includes(e.lang) ||
(e.lang === 'CUSTOM' &&
typeof customVoiceName !== 'undefined')
)
})
.map((e) => {
return {
name: e.name,
lang: e.lang === 'CUSTOM' ? customVoiceName : e.lang,
lookup_region: e.lookup_region.replace('_', '-'),
}
})
for (const voiceSubFolderMapping of voiceLangMapping) {
const voiceSubFolder = path.join(
OPERATOR_SOURCE_FOLDER,
name,
config.dir_name.voice.main,
voiceSubFolderMapping.name
)
const voiceFileList = file.readdirSync(voiceSubFolder)
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') &&
voiceFileList.includes(`${item}.ogg`) &&
(voiceSubFolderMapping.name === 'kr' ||
voiceSubFolderMapping.name === 'en')
) {
console.log(
`Voice folder ${voiceSubFolderMapping.name} for ${name} has ${item}.ogg`
)
}
if (
!voiceFileList.includes(`${item}.ogg`) &&
// make an exception
!item.endsWith('043')
) {
err.push(
`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)
}
// check whether voice files has been added
const customVoiceName = voiceLangs.filter(
(i) => !config.dir_name.voice.sub.map((e) => e.lang).includes(i)
)[0]
const voiceLangMapping = config.dir_name.voice.sub
.filter((e) => {
return (
voiceLangs.includes(e.lang) ||
(e.lang === 'CUSTOM' &&
typeof customVoiceName !== 'undefined')
)
})
.map((e) => {
return {
name: e.name,
lang: e.lang === 'CUSTOM' ? customVoiceName : e.lang,
lookup_region: e.lookup_region.replace('_', '-'),
}
})
for (const voiceSubFolderMapping of voiceLangMapping) {
const voiceSubFolder = path.join(
OPERATOR_SOURCE_FOLDER,
name,
config.dir_name.voice.main,
voiceSubFolderMapping.name
)
const voiceFileList = file.readdirSync(voiceSubFolder)
voiceList[voiceSubFolderMapping.lookup_region].map((item) => {
// an exception for detecting file existence
if (
item.endsWith('043') &&
voiceFileList.includes(`${item}.ogg`) &&
(voiceSubFolderMapping.name === 'kr' ||
voiceSubFolderMapping.name === 'en')
) {
console.log(
`Voice folder ${voiceSubFolderMapping.name} for ${name} has ${item}.ogg`
)
}
if (
!voiceFileList.includes(`${item}.ogg`) &&
// make an exception
!item.endsWith('043')
) {
err.push(
`Voice folder ${voiceSubFolderMapping.name} for ${name} is missing ${item}.ogg`
)
}
})
}
}
return err

View File

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