Download apps/server/src/services/audioMixService.ts from phucsd/olokaflow: direct link, hf CLI and curl.
- Browser
- Download file 3.19 kB
-
https://huggingface.co/spaces/phucsd/olokaflow/resolve/main/apps/server/src/services/audioMixService.ts
- Command line
-
hf download hf://spaces/phucsd/olokaflow/apps/server/src/services/audioMixService.ts
-
curl -L -o audioMixService.ts https://huggingface.co/spaces/phucsd/olokaflow/resolve/main/apps/server/src/services/audioMixService.ts
3.19 kB
| import fs from 'node:fs'; | |
| import path from 'node:path'; | |
| import { PROJECTS_DIR } from '../db/database.js'; | |
| import type { Project } from '@olokaflow/shared'; | |
| export interface BgmTrackSpec { | |
| id: string; | |
| name: string; | |
| mood: string; | |
| bpm: number; | |
| description: string; | |
| } | |
| export const BGM_CATALOG: BgmTrackSpec[] = [ | |
| { | |
| id: 'upbeat-tech', | |
| name: 'Upbeat Future Tech (124 BPM)', | |
| mood: 'Năng lượng, Hiện đại, AI & SaaS', | |
| bpm: 124, | |
| description: 'Nhịp synth hiện đại kèm sub-bass rõ nét, tự động Ducking khi có giọng đọc', | |
| }, | |
| { | |
| id: 'tiktok-viral-pop', | |
| name: 'TikTok Viral Hook Beat (128 BPM)', | |
| mood: 'Sôi động, Bắt tai, Review & Bán hàng', | |
| bpm: 128, | |
| description: 'Nhịp trống dồn dập giữ chân người xem trong 3 giây đầu tiên', | |
| }, | |
| { | |
| id: 'corporate-clean', | |
| name: 'Enterprise Vision (112 BPM)', | |
| mood: 'Chuyên nghiệp, Uy tín, B2B & Tài chính', | |
| bpm: 112, | |
| description: 'Tiết tấu piano kết hợp đệm điện tử tinh tế cho giới thiệu doanh nghiệp', | |
| }, | |
| { | |
| id: 'luxury-ambient', | |
| name: 'Obsidian Gold Luxury (96 BPM)', | |
| mood: 'Sang trọng, Mỹ phẩm, Thời trang & Bất động sản', | |
| bpm: 96, | |
| description: 'Không gian âm thanh sâu lắng, tôn vinh hình ảnh sản phẩm cao cấp', | |
| }, | |
| { | |
| id: 'lofi-focus', | |
| name: 'Warm Storytelling Lo-Fi (88 BPM)', | |
| mood: 'Gần gũi, Kể chuyện, Giáo dục & Podcast', | |
| bpm: 88, | |
| description: 'Giai điệu ấm áp không lấn át tần số giọng nói tiếng Việt', | |
| }, | |
| ]; | |
| export const SFX_CATALOG = [ | |
| { id: 'whoosh-soft', name: 'Soft Air Whoosh', trigger: 'scene-transition' }, | |
| { id: 'pop-spring', name: 'Elastic UI Pop', trigger: 'card-entrance' }, | |
| { id: 'click-ui', name: 'Tactile Cursor Click', trigger: 'button-press' }, | |
| { id: 'riser-hit', name: 'Cinematic Sub Riser', trigger: 'hook-reveal' }, | |
| { id: 'ding-success', name: 'Crystal Notification Ding', trigger: 'cta-lockup' }, | |
| ]; | |
| function formatSrtTime(sec: number): string { | |
| const hrs = Math.floor(sec / 3600); | |
| const mins = Math.floor((sec % 3600) / 60); | |
| const secs = Math.floor(sec % 60); | |
| const ms = Math.round((sec - Math.floor(sec)) * 1000); | |
| const pad = (n: number, len = 2) => String(n).padStart(len, '0'); | |
| return `${pad(hrs)}:${pad(mins)}:${pad(secs)},${pad(ms, 3)}`; | |
| } | |
| /** | |
| * Generates an `.srt` subtitle file for the project's Social Publish Kit. | |
| */ | |
| export function generateProjectSrtFile(project: Project): string { | |
| const projectDir = path.join(PROJECTS_DIR, project.id); | |
| fs.mkdirSync(projectDir, { recursive: true }); | |
| let cursor = 0; | |
| const blocks: string[] = []; | |
| let idx = 1; | |
| for (const scene of project.scenes) { | |
| const start = cursor; | |
| const end = cursor + (scene.durationSec || 4); | |
| cursor = end; | |
| blocks.push( | |
| `${idx}\n${formatSrtTime(start)} --> ${formatSrtTime(end)}\n${scene.narrationText.trim()}\n` | |
| ); | |
| idx++; | |
| } | |
| const srtContent = blocks.join('\n'); | |
| const srtPath = path.join(projectDir, 'subtitles.srt'); | |
| fs.writeFileSync(srtPath, srtContent, 'utf8'); | |
| return `/api/projects/${project.id}/srt`; | |
| } | |