creatomate 가사 정합

This commit is contained in:
jaehwang committed 2026-01-21 04:18:14 +00:00
1 parent 94be8a0746
commit 198513f237
4 files changed
+141 -49

No files matched your search

+90
View File
@@ -58,6 +58,77 @@ CACHE_TTL_SECONDS = 300
# 모듈 레벨 공유 HTTP 클라이언트 (커넥션 풀 재사용)
_shared_client: httpx.AsyncClient | None = None
text_template_v_1 = {
"type": "composition",
"track": 3,
"elements": [
{
"type": "text",
"time": 0,
"y": "80%",
"width": "100%",
"height": "40%",
"x_alignment": "50%",
"y_alignment": "50%",
"text": "Lorem ipsum dolor sit amet, consectetur ad",
"font_family": "Noto Sans",
"font_weight": "700",
"font_size": "8 vmin",
"background_color": "rgba(216,216,216,0)",
"background_x_padding": "33%",
"background_y_padding": "7%",
"background_border_radius": "28%",
"fill_color": "#ffffff",
"stroke_color": "#333333",
"stroke_width": "1.25 vmin",
}
]
}
text_template_v_2 = {
"type": "composition",
"track": 3,
"elements": [
{
"type": "text",
"time": 0,
"x": "7.7233%",
"y": "89.5758%",
"width": "84.5534%",
"height": "5.7015%",
"x_anchor": "0%",
"y_anchor": "0%",
"y_alignment": "100%",
"font_family": "Noto Sans",
"font_weight": "700",
"font_size": "6.9999 vmin",
"fill_color": "#ffffff"
}
]
}
text_template_h_1 = {
"type": "composition",
"track": 3,
"elements": [
{
"type": "text",
"time": 0,
"x": "10%",
"y": "80%",
"width": "80%",
"height": "15%",
"x_anchor": "0%",
"y_anchor": "0%",
"x_alignment": "50%",
"font_family": "Noto Sans",
"font_weight": "700",
"font_size": "5.9998 vmin",
"fill_color": "#ffffff",
"stroke_color": "#333333",
"stroke_width": "0.2 vmin"
}
]
}
async def get_shared_client() -> httpx.AsyncClient:
"""공유 HTTP 클라이언트를 반환합니다. 없으면 생성합니다."""
@@ -470,3 +541,22 @@ class CreatomateService:
)
return new_template
def lining_lyric(self, text_template: dict, lyric_index: int, lyric_text: str, start_sec: float, end_sec: float) -> dict:
duration = end_sec - start_sec
text_scene = copy.deepcopy(text_template)
text_scene["name"] = f"Caption-{lyric_index}"
text_scene["duration"] = duration
text_scene["time"] = start_sec
text_scene["elements"][0]["name"] = f"lyric-{lyric_index}"
text_scene["elements"][0]["text"] = lyric_text
return text_scene
def get_text_template(self):
match self.orientation:
case "vertical":
return text_template_v_1
case "horizontal":
return text_template_h_1
+7 -7
View File
@@ -197,19 +197,19 @@ class SunoService:
"audio_id" : audio_id
}
async with httpx.AsyncClient() as client:
response = await client.get(
response = await client.post(
f"{self.BASE_URL}/generate/get-timestamped-lyrics",
headers=self.headers,
json = payload,
json=payload,
timeout=30.0,
)
response.raise_for_status()
data = response.json()
if data is None:
if not data or not data['data']:
raise ValueError("Suno API returned empty response for task status")
return data['alignedWords']
return data['data']['alignedWords']
def parse_status_response(self, result: dict | None) -> PollingSongResponse:
"""Suno API 상태 응답을 파싱하여 PollingSongResponse로 변환합니다.
@@ -355,12 +355,12 @@ class SunoService:
results.append({
'text': sentence,
'startS': word_start['startS'],
'endS': word_end['endS'],
'start_sec': word_start['startS'],
'end_sec': word_end['endS'],
})
search_pos = found_pos + len(norm_sentence)
else:
results.append({'text': sentence, 'startS': None, 'endS': None})
results.append({'text': sentence, 'start_sec': None, 'end_sec': None})
return results