[O] Parallelize song preparation

This commit is contained in:
2025-11-23 14:41:22 +08:00
parent 93b674942d
commit 2febbea6ec
2 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ Practice Japanese Karaoke lyrics reading and typing at the same time with KaraDa
* [x] Update an existing playlist
* [ ] Allow users to correct lyric pronunciations through correction feedback
* [ ] Correct lyrics timing inconsistencies (i.e. 网易云的歌词因为是业余用户上传的,时间戳不一定准确。但是 waveform 里面可以分析出每句歌词的具体开始结束时间,也许可以自动修正)
* [ ] Processing lyrics and audio should be parallel
* [x] Processing lyrics and audio should be parallel
## Development server
+7 -6
View File
@@ -153,16 +153,13 @@ export const prepareSong = async (songId: number) => {
songProcessingStatus.set(songId, state)
const addTask = (id: string, task: string) => ({ id, task, progress: 0 }).also(it => state.items.push(it))
try {
const processLyrics = async () => {
// 1. Get Lyrics
const taskLyrics = addTask('lyrics', '从网易云获取歌词')
const raw = await getLyricsRaw(songId)
taskLyrics.progress = 1
if (raw.lang !== 'jpn') {
addTask('error', '错误: 不是日语歌曲').progress = -1
return state.status = 'error'
}
if (raw.lang !== 'jpn') throw new Error('不是日语歌曲')
// 2. AI Process
const taskAI = addTask('ai', 'AI 标注歌词读音')
@@ -174,7 +171,9 @@ export const prepareSong = async (songId: number) => {
await dbs.lyricsProcessed.replaceOne({ _id: songId as any }, { _id: songId, data: lrc }, { upsert: true })
taskAI.progress = 1
}
}
const processMusic = async () => {
// 3. Audio
const taskAudio = addTask('music', '从网易云获取音乐')
await getSongUrl(songId)
@@ -192,9 +191,11 @@ export const prepareSong = async (songId: number) => {
addTask('error', `错误: ${e.message}`).progress = -1
// Don't fail the whole process, just this step
}
}
try {
await Promise.all([processLyrics(), processMusic()])
state.status = 'done'
} catch (e) {
addTask('error', `错误: ${eToString(e)}`).progress = -1
state.status = 'error'