feature: parsing signer for TTML

This commit is contained in:
alikia2x (寒寒) 2024-10-28 23:21:45 +08:00
parent 5af6992632
commit f50ff5c588
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
5 changed files with 19 additions and 20 deletions

View File

@ -4,8 +4,6 @@
import type { LyricPos } from './type';
import type { Spring } from '@core/graphics/spring/spring';
const viewportWidth = document.documentElement.clientWidth;
export let line: ScriptItem;
export let index: number;
export let debugMode: Boolean;
@ -150,25 +148,14 @@
</span>
{/if}
<span
class={`text-white text-[2rem] leading-9 lg:text-5xl lg:leading-[4rem] font-semibold text-shadow-lg mr-4
${isCurrentLyric ? 'text-glow' : ''}`}
class={`text-white text-[2rem] leading-9 lg:text-5xl lg:leading-[4rem] font-semibold mr-4`}
>
{line.text}
</span>
{#if line.translation}
<br />
<span class={`pl-2 relative text-xl lg:text-2xl top-2 duration-300`}>
<span class={`pl-2 relative text-xl lg:text-2xl top-2 duration-300 text-white`}>
{line.translation}
</span>
{/if}
</div>
<style>
.text-glow {
text-shadow:
0 0 3px #ffffff2c,
0 0 6px #ffffff2c,
0 15px 30px rgba(0, 0, 0, 0.11),
0 5px 15px rgba(0, 0, 0, 0.08);
}
</style>

View File

@ -1,6 +1,7 @@
import type { LrcJsonData } from '../type';
import { parseTTML as ttmlParser } from './parser';
import type { LyricLine } from './ttml-types';
export * from './writer';
export type * from './ttml-types';
@ -9,11 +10,22 @@ export function parseTTML(text: string) {
const lyricLines = ttmlParser(text).lyricLines;
lyrics = {
scripts: lyricLines.map((value: LyricLine, index: number, array: LyricLine[]) => {
let words = value.words.length == 0 ? undefined : value.words;
if (words) {
words = words.map((word) => {
let r = word;
r.startTime /= 1000;
r.endTime /= 1000;
return r;
});
}
return {
text: value.words.map((word) => word.word).join(''),
start: value.startTime / 1000,
end: value.endTime / 1000,
translation: value.translatedLyric || undefined
translation: value.translatedLyric || undefined,
singer: value.singer || undefined,
words: words
};
})
};

View File

@ -78,6 +78,7 @@ export function parseTTML(ttmlText: string): TTMLLyric {
lineEl.getAttribute("ttm:agent") !== mainAgentId,
startTime: 0,
endTime: 0,
singer: ""
};
if (isBG) line.isDuet = isDuet;
let haveBg = false;
@ -101,6 +102,8 @@ export function parseTTML(ttmlText: string): TTMLLyric {
line.translatedLyric = wordEl.innerHTML;
} else if (role === "x-roman") {
line.romanLyric = wordEl.innerHTML;
} else if (role === "x-singer") {
line.singer = wordEl.innerHTML;
}
} else if (wordEl.hasAttribute("begin") && wordEl.hasAttribute("end")) {
const word: LyricWord = {

View File

@ -23,4 +23,5 @@ export interface LyricLine {
isDuet: boolean;
startTime: number;
endTime: number;
singer: string;
}

View File

@ -12,8 +12,4 @@
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
<link
href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
</html>