배경음악 기능 추가
This commit is contained in:
1 parent
2c8c16c288
commit
ec3e0159e8
7 files changed
+166
-74
No files matched your search
+16
-10
@@ -55,11 +55,12 @@ generate() 호출 시 callback_url 파라미터를 전달하면 생성 완료
|
||||
- 동일 task_id에 대해 여러 콜백 수신 가능 (멱등성 처리 필요)
|
||||
"""
|
||||
|
||||
from typing import Any, List, Optional
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
from app.song.schemas.song_schema import PollingSongResponse, SongClipData
|
||||
from app.utils.bgm_lyrics import get_random_bgm_lyrics
|
||||
from app.utils.logger import get_logger
|
||||
from config import apikey_settings, recovery_settings
|
||||
|
||||
@@ -102,9 +103,10 @@ class SunoService:
|
||||
|
||||
async def generate(
|
||||
self,
|
||||
prompt: str,
|
||||
prompt: str | None = None,
|
||||
genre: str | None = None,
|
||||
callback_url: str | None = None,
|
||||
instrumental: bool = False,
|
||||
) -> str:
|
||||
"""
|
||||
음악 생성 요청
|
||||
@@ -115,6 +117,7 @@ class SunoService:
|
||||
genre: 음악 장르 (예: "K-Pop", "Pop", "R&B", "Hip-Hop", "Ballad", "EDM")
|
||||
None일 경우 style 파라미터를 전송하지 않음
|
||||
callback_url: 생성 완료 시 알림 받을 URL (None일 경우 config에서 기본값 사용)
|
||||
instrumental: True이면 BGM 전용 — 더미 가사로 60초 길이를 유도하고 보컬 없이 생성
|
||||
|
||||
Returns:
|
||||
task_id: 작업 추적용 ID
|
||||
@@ -124,23 +127,26 @@ class SunoService:
|
||||
- 다운로드 URL: 2-3분 내 생성
|
||||
- 생성되는 노래는 약 1분 이내의 길이
|
||||
"""
|
||||
# 정확히 1분 길이의 노래 생성을 위한 프롬프트 조건 추가
|
||||
formatted_prompt = f"[Song Duration: Exactly 1 minute - Must be precisely 60 seconds]\n{prompt}"
|
||||
|
||||
# callback_url이 없으면 config에서 기본값 사용 (Suno API 필수 파라미터)
|
||||
actual_callback_url = callback_url or apikey_settings.SUNO_CALLBACK_URL
|
||||
|
||||
if instrumental:
|
||||
bgm_lyrics, bgm_version = get_random_bgm_lyrics()
|
||||
formatted_prompt = f"[Song Duration: Around 1 minute - Must be around 60 seconds]\n{bgm_lyrics}"
|
||||
logger.info(f"[Suno] BGM 더미 가사 버전 {bgm_version} 선택됨")
|
||||
else:
|
||||
formatted_prompt = (
|
||||
f"[Song Duration: Exactly 1 minute - Must be precisely 60 seconds]\n{prompt}"
|
||||
)
|
||||
|
||||
payload: dict[str, Any] = {
|
||||
"model": "V5",
|
||||
"customMode": True,
|
||||
"instrumental": False,
|
||||
"instrumental": instrumental,
|
||||
"prompt": formatted_prompt,
|
||||
"callBackUrl": actual_callback_url,
|
||||
}
|
||||
|
||||
# genre가 있을 때만 style 추가
|
||||
if genre:
|
||||
payload["style"] = genre
|
||||
payload["style"] = f"{genre}, around 60 seconds" if instrumental else genre
|
||||
|
||||
last_error: Exception | None = None
|
||||
|
||||
|
||||
Reference in new issue
Block a user