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