vidspotai-shared 1.0.133 → 1.0.135

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/lib/globals/aiModels/providers/falVideo.d.ts +34 -0
  2. package/lib/globals/aiModels/providers/falVideo.d.ts.map +1 -0
  3. package/lib/globals/aiModels/providers/falVideo.js +102 -0
  4. package/lib/globals/index.d.ts +1 -0
  5. package/lib/globals/index.d.ts.map +1 -1
  6. package/lib/globals/index.js +1 -0
  7. package/lib/globals/musicStudio.d.ts +90 -0
  8. package/lib/globals/musicStudio.d.ts.map +1 -0
  9. package/lib/globals/musicStudio.js +221 -0
  10. package/lib/globals/types.d.ts +10 -1
  11. package/lib/globals/types.d.ts.map +1 -1
  12. package/lib/globals/types.js +12 -0
  13. package/lib/models/index.d.ts +1 -0
  14. package/lib/models/index.d.ts.map +1 -1
  15. package/lib/models/index.js +1 -0
  16. package/lib/models/musicJob.model.d.ts +73 -0
  17. package/lib/models/musicJob.model.d.ts.map +1 -0
  18. package/lib/models/musicJob.model.js +2 -0
  19. package/lib/services/aiGen/providers/fal/falMusic.service.d.ts +63 -0
  20. package/lib/services/aiGen/providers/fal/falMusic.service.d.ts.map +1 -0
  21. package/lib/services/aiGen/providers/fal/falMusic.service.js +310 -0
  22. package/lib/services/aiGen/providers/fal/falVideo.service.d.ts +39 -0
  23. package/lib/services/aiGen/providers/fal/falVideo.service.d.ts.map +1 -0
  24. package/lib/services/aiGen/providers/fal/falVideo.service.js +266 -0
  25. package/lib/services/aiGen/providers/fal/index.d.ts +1 -0
  26. package/lib/services/aiGen/providers/fal/index.d.ts.map +1 -1
  27. package/lib/services/aiGen/providers/fal/index.js +1 -0
  28. package/lib/services/firestore.service.d.ts +2 -0
  29. package/lib/services/firestore.service.d.ts.map +1 -1
  30. package/lib/services/firestore.service.js +3 -0
  31. package/lib/services/index.d.ts +1 -0
  32. package/lib/services/index.d.ts.map +1 -1
  33. package/lib/services/index.js +1 -0
  34. package/lib/services/music/index.d.ts +3 -0
  35. package/lib/services/music/index.d.ts.map +1 -0
  36. package/lib/services/music/index.js +18 -0
  37. package/lib/services/music/musicLyricWriter.d.ts +25 -0
  38. package/lib/services/music/musicLyricWriter.d.ts.map +1 -0
  39. package/lib/services/music/musicLyricWriter.js +58 -0
  40. package/lib/services/music/musicLyrics.d.ts +66 -0
  41. package/lib/services/music/musicLyrics.d.ts.map +1 -0
  42. package/lib/services/music/musicLyrics.js +258 -0
  43. package/package.json +1 -1
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLyricSections = parseLyricSections;
4
+ exports.lyricLines = lyricLines;
5
+ exports.toLrc = toLrc;
6
+ exports.toElevenLabsSections = toElevenLabsSections;
7
+ exports.alignLyrics = alignLyrics;
8
+ exports.composeStylePrompt = composeStylePrompt;
9
+ exports.composeStyleTags = composeStyleTags;
10
+ const TAG_LINE = /^\s*\[([^\]]{1,40})\]\s*$/;
11
+ /** Splits `[Verse]` / `[Chorus]`-tagged lyrics into sections. Untagged text is one Verse. */
12
+ function parseLyricSections(lyrics) {
13
+ const sections = [];
14
+ let current = null;
15
+ for (const raw of lyrics.split(/\r?\n/)) {
16
+ const line = raw.trim();
17
+ if (!line)
18
+ continue;
19
+ const tag = TAG_LINE.exec(line);
20
+ if (tag) {
21
+ current = { name: (tag[1] ?? "Verse").trim(), lines: [] };
22
+ sections.push(current);
23
+ continue;
24
+ }
25
+ if (!current) {
26
+ current = { name: "Verse", lines: [] };
27
+ sections.push(current);
28
+ }
29
+ current.lines.push(line);
30
+ }
31
+ return sections.filter((s) => s.lines.length > 0 || /inst|solo|break|intro|outro/i.test(s.name));
32
+ }
33
+ /** The sung lines only — section tags and blank lines dropped. */
34
+ function lyricLines(lyrics) {
35
+ return parseLyricSections(lyrics).flatMap((s) => s.lines);
36
+ }
37
+ /**
38
+ * DiffRhythm wants LRC: every line stamped `[mm:ss.xx]`, at least two
39
+ * sections. Lines are paced evenly across the track with a breath between
40
+ * sections, starting after a short intro.
41
+ */
42
+ function toLrc(lyrics, durationSec) {
43
+ const sections = parseLyricSections(lyrics).filter((s) => s.lines.length > 0);
44
+ const total = sections.reduce((n, s) => n + s.lines.length, 0);
45
+ if (total === 0)
46
+ return "";
47
+ const intro = Math.min(10, durationSec * 0.08);
48
+ const gaps = Math.max(0, sections.length - 1) * 4;
49
+ const usable = Math.max(total, durationSec * 0.85 - intro - gaps);
50
+ const step = Math.min(4.5, usable / total);
51
+ let t = intro;
52
+ const out = [];
53
+ sections.forEach((section, i) => {
54
+ if (i > 0)
55
+ t += 4;
56
+ for (const line of section.lines) {
57
+ if (t > durationSec - 2)
58
+ return;
59
+ out.push(`${lrcStamp(t)}${line}`);
60
+ t += step;
61
+ }
62
+ });
63
+ return out.join("\n");
64
+ }
65
+ function lrcStamp(sec) {
66
+ const m = Math.floor(sec / 60);
67
+ const s = sec - m * 60;
68
+ return `[${String(m).padStart(2, "0")}:${s.toFixed(2).padStart(5, "0")}]`;
69
+ }
70
+ /**
71
+ * ElevenLabs composition plan sections from tagged lyrics. Each section gets a
72
+ * share of `totalSec` proportional to its line count (instrumental tags get a
73
+ * fixed share), clamped to the provider's 3–120 s per section; lines are capped
74
+ * at 200 characters. Long untagged lyrics are chunked into 4-line sections so
75
+ * no section has to exceed 120 s.
76
+ */
77
+ function toElevenLabsSections(lyrics, totalSec) {
78
+ const parsed = parseLyricSections(lyrics).flatMap((s) => s.lines.length > 8
79
+ ? chunk(s.lines, 4).map((lines, i) => ({ name: i === 0 ? s.name : `${s.name} ${i + 1}`, lines }))
80
+ : [s]);
81
+ if (parsed.length === 0)
82
+ return [];
83
+ const weight = (s) => (s.lines.length === 0 ? 2 : s.lines.length);
84
+ const totalWeight = parsed.reduce((n, s) => n + weight(s), 0);
85
+ return parsed.map((s) => ({
86
+ section_name: s.name.slice(0, 100),
87
+ duration_ms: Math.round(clamp((totalSec * weight(s)) / totalWeight, 3, 120) * 1000),
88
+ positive_local_styles: [],
89
+ negative_local_styles: [],
90
+ lines: s.lines.map((l) => l.slice(0, 200)),
91
+ }));
92
+ }
93
+ function chunk(items, size) {
94
+ const out = [];
95
+ for (let i = 0; i < items.length; i += size)
96
+ out.push(items.slice(i, i + size));
97
+ return out;
98
+ }
99
+ function clamp(n, lo, hi) {
100
+ return Math.min(Math.max(n, lo), hi);
101
+ }
102
+ const norm = (w) => w
103
+ .toLowerCase()
104
+ .normalize("NFKD")
105
+ .replace(/[̀-ͯ]/g, "")
106
+ .replace(/[^\p{L}\p{N}']/gu, "")
107
+ .replace(/'/g, "");
108
+ function wordsMatch(a, b) {
109
+ if (!a || !b)
110
+ return false;
111
+ if (a === b)
112
+ return true;
113
+ if (a.length >= 4 && b.length >= 4 && (a.startsWith(b) || b.startsWith(a)))
114
+ return true;
115
+ return a.length >= 5 && editDistance(a, b) <= 1;
116
+ }
117
+ function editDistance(a, b) {
118
+ const dp = Array.from({ length: b.length + 1 }, (_, j) => j);
119
+ for (let i = 1; i <= a.length; i++) {
120
+ let prev = dp[0] ?? 0;
121
+ dp[0] = i;
122
+ for (let j = 1; j <= b.length; j++) {
123
+ const tmp = dp[j] ?? 0;
124
+ dp[j] = Math.min(tmp + 1, (dp[j - 1] ?? 0) + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
125
+ prev = tmp;
126
+ }
127
+ }
128
+ return dp[b.length] ?? 0;
129
+ }
130
+ /** How far ahead in the transcript a lyric word may match (skips ad-libs / misheard words). */
131
+ const LOOKAHEAD = 12;
132
+ /**
133
+ * Times lyric lines against a word-level transcript of the track. With known
134
+ * lyrics, each line's words are matched in order against the transcript
135
+ * (fuzzy, with a lookahead so ad-libs and misheard words don't derail it);
136
+ * lines that matched nothing are interpolated between their neighbours.
137
+ * Without lyrics the transcript itself is split into lines at pauses.
138
+ */
139
+ function alignLyrics(words, lyrics, trackSec) {
140
+ const transcript = words.filter((w) => norm(w.text));
141
+ const lines = lyrics ? lyricLines(lyrics) : [];
142
+ if (lines.length === 0)
143
+ return linesFromTranscript(transcript);
144
+ if (transcript.length === 0)
145
+ return [];
146
+ let cursor = 0;
147
+ const timed = lines.map((text) => {
148
+ const tokens = text.split(/\s+/).map(norm).filter(Boolean);
149
+ let start;
150
+ let end;
151
+ for (const token of tokens) {
152
+ const limit = Math.min(transcript.length, cursor + LOOKAHEAD);
153
+ for (let k = cursor; k < limit; k++) {
154
+ const word = transcript[k];
155
+ if (word && wordsMatch(token, norm(word.text))) {
156
+ start ?? (start = word.start);
157
+ end = word.end;
158
+ cursor = k + 1;
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ return { text, start, end };
164
+ });
165
+ // Interpolate unmatched lines between the nearest timed neighbours.
166
+ const startAt = (idx) => timed[idx]?.start;
167
+ for (let i = 0; i < timed.length; i++) {
168
+ if (startAt(i) !== undefined)
169
+ continue;
170
+ let j = i;
171
+ while (j < timed.length && startAt(j) === undefined)
172
+ j++;
173
+ const from = i > 0 ? (timed[i - 1]?.end ?? 0) : (transcript[0]?.start ?? 0);
174
+ const to = j < timed.length ? (startAt(j) ?? trackSec) : Math.min(trackSec, from + (j - i) * 3);
175
+ const step = Math.max(0.5, (to - from) / (j - i));
176
+ for (let k = i; k < j; k++) {
177
+ const line = timed[k];
178
+ if (!line)
179
+ continue;
180
+ line.start = from + step * (k - i);
181
+ line.end = from + step * (k - i + 1);
182
+ }
183
+ i = j - 1;
184
+ }
185
+ return timed.map((l) => ({ text: l.text, start: round2(l.start ?? 0), end: round2(l.end ?? l.start ?? 0) }));
186
+ }
187
+ /** Pause long enough to start a new line, and the most words a line holds. */
188
+ const LINE_GAP_SEC = 0.7;
189
+ const MAX_LINE_WORDS = 10;
190
+ function linesFromTranscript(words) {
191
+ const out = [];
192
+ let buf = [];
193
+ const flush = () => {
194
+ const first = buf[0];
195
+ const last = buf[buf.length - 1];
196
+ if (!first || !last)
197
+ return;
198
+ out.push({
199
+ text: buf.map((w) => w.text.trim()).join(" ").replace(/\s+([,.!?])/g, "$1"),
200
+ start: round2(first.start),
201
+ end: round2(last.end),
202
+ });
203
+ buf = [];
204
+ };
205
+ for (const w of words) {
206
+ const prev = buf[buf.length - 1];
207
+ if (prev && (w.start - prev.end > LINE_GAP_SEC || buf.length >= MAX_LINE_WORDS || /[.!?]$/.test(prev.text)))
208
+ flush();
209
+ buf.push(w);
210
+ }
211
+ flush();
212
+ return out;
213
+ }
214
+ const round2 = (n) => Math.round(n * 100) / 100;
215
+ const VOCAL_PHRASE = {
216
+ female: "female lead vocals",
217
+ male: "male lead vocals",
218
+ duet: "male and female duet vocals with harmonies",
219
+ choir: "lead vocal with layered choir harmonies and backing vocals",
220
+ };
221
+ /**
222
+ * One natural-language style brief from the studio's controls. Every model
223
+ * reads genre / mood / tempo / vocal direction from text, so the controls
224
+ * become a leading descriptor line followed by the user's own description.
225
+ */
226
+ function composeStylePrompt(input, maxChars) {
227
+ const parts = [];
228
+ if (input.genres?.length)
229
+ parts.push(input.genres.join(", "));
230
+ if (input.moods?.length)
231
+ parts.push(input.moods.join(", "));
232
+ if (input.bpm)
233
+ parts.push(`${input.bpm} BPM`);
234
+ if (input.instrumental)
235
+ parts.push("instrumental, no vocals");
236
+ else {
237
+ if (input.vocalStyle)
238
+ parts.push(VOCAL_PHRASE[input.vocalStyle]);
239
+ if (input.language && input.language.toLowerCase() !== "english")
240
+ parts.push(`sung in ${input.language}`);
241
+ }
242
+ const head = parts.join(", ");
243
+ const body = input.prompt.trim();
244
+ const full = head && body ? `${head}. ${body}` : head || body;
245
+ return full.slice(0, maxChars);
246
+ }
247
+ /** Comma-separated tag string for ACE-Step (`tags`). */
248
+ function composeStyleTags(input) {
249
+ const tags = [
250
+ ...(input.genres ?? []),
251
+ ...(input.moods ?? []),
252
+ ...(input.bpm ? [`${input.bpm} bpm`] : []),
253
+ ...(input.instrumental ? ["instrumental"] : input.vocalStyle ? [VOCAL_PHRASE[input.vocalStyle]] : []),
254
+ ];
255
+ if (tags.length === 0)
256
+ return input.prompt.trim().slice(0, 300);
257
+ return tags.join(", ").toLowerCase();
258
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidspotai-shared",
3
- "version": "1.0.133",
3
+ "version": "1.0.135",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "exports": {