배경음악 기능 추가 및 예외 처리 수정
This commit is contained in:
1 parent
cf27da30b4
commit
a155a98767
12 files changed
+248
-66
No files matched your search
@@ -276,6 +276,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
|
||||
try {
|
||||
const language = LANGUAGE_MAP[selectedLang] || 'Korean';
|
||||
const isInstrumental = selectedType === '배경음악';
|
||||
|
||||
// 1. 가사 생성 요청
|
||||
console.log('[SoundStudio] Sending m_id:', mId);
|
||||
@@ -287,37 +288,13 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
region: businessInfo.region,
|
||||
task_id: imageTaskId,
|
||||
orientation,
|
||||
...(isInstrumental && { instrumental: true }),
|
||||
});
|
||||
|
||||
if (!lyricResponse.success || !lyricResponse.task_id) {
|
||||
throw new Error(lyricResponse.error_message || t('soundStudio.lyricGenerationFailed'));
|
||||
}
|
||||
|
||||
// 2. 가사 생성 상태 폴링 → 완료 시 상세 조회
|
||||
setStatusMessage(t('soundStudio.generatingLyrics'));
|
||||
const lyricDetailResponse = await waitForLyricComplete(
|
||||
lyricResponse.task_id,
|
||||
(status: string) => {
|
||||
if (status === 'processing') {
|
||||
setStatusMessage(t('soundStudio.generatingLyrics'));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!lyricDetailResponse.lyric_result) {
|
||||
throw new Error(t('soundStudio.lyricNotReceived'));
|
||||
}
|
||||
|
||||
// "I'm sorry" 체크
|
||||
if (lyricDetailResponse.lyric_result.includes("I'm sorry")) {
|
||||
throw new Error(t('soundStudio.lyricGenerationError'));
|
||||
}
|
||||
|
||||
setLyrics(lyricDetailResponse.lyric_result);
|
||||
|
||||
setStatus('generating_song');
|
||||
setStatusMessage(t('soundStudio.generatingSong'));
|
||||
|
||||
const genreMap: Record<string, string> = {
|
||||
'자동 선택': 'pop',
|
||||
'K-POP': 'kpop',
|
||||
@@ -329,10 +306,39 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
'ROCK': 'rock',
|
||||
};
|
||||
|
||||
let songLyrics: string | undefined;
|
||||
|
||||
if (!isInstrumental) {
|
||||
// 2. 가사 생성 상태 폴링 → 완료 시 상세 조회
|
||||
setStatusMessage(t('soundStudio.generatingLyrics'));
|
||||
const lyricDetailResponse = await waitForLyricComplete(
|
||||
lyricResponse.task_id,
|
||||
(status: string) => {
|
||||
if (status === 'processing') {
|
||||
setStatusMessage(t('soundStudio.generatingLyrics'));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!lyricDetailResponse.lyric_result) {
|
||||
throw new Error(t('soundStudio.lyricNotReceived'));
|
||||
}
|
||||
|
||||
// "I'm sorry" 체크
|
||||
if (lyricDetailResponse.lyric_result.includes("I'm sorry")) {
|
||||
throw new Error(t('soundStudio.lyricGenerationError'));
|
||||
}
|
||||
|
||||
setLyrics(lyricDetailResponse.lyric_result);
|
||||
songLyrics = lyricDetailResponse.lyric_result;
|
||||
}
|
||||
|
||||
setStatus('generating_song');
|
||||
setStatusMessage(t('soundStudio.generatingSong'));
|
||||
|
||||
const songResponse = await generateSong(imageTaskId, {
|
||||
genre: genreMap[selectedGenre] || 'pop',
|
||||
language,
|
||||
lyrics: lyricDetailResponse.lyric_result,
|
||||
...(isInstrumental ? { instrumental: true, lyrics: '' } : { language, lyrics: songLyrics }),
|
||||
});
|
||||
|
||||
if (!songResponse.success) {
|
||||
@@ -351,7 +357,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
setStatus('polling');
|
||||
setStatusMessage(t('soundStudio.generatingSong'));
|
||||
|
||||
await resumePolling(songResponse.task_id, songResponse.song_id, lyricDetailResponse.lyric_result, 0);
|
||||
await resumePolling(songResponse.task_id, songResponse.song_id, songLyrics ?? '', 0);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Music generation failed:', error);
|
||||
@@ -412,7 +418,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
<div className="sound-type-grid">
|
||||
{[
|
||||
{ key: '보컬', label: t('soundStudio.soundTypeVocal'), disabled: false },
|
||||
{ key: '배경음악', label: t('soundStudio.soundTypeBGM'), disabled: true },
|
||||
{ key: '배경음악', label: t('soundStudio.soundTypeBGM'), disabled: false },
|
||||
].map(({ key, label, disabled }) => (
|
||||
<button
|
||||
key={key}
|
||||
@@ -483,8 +489,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
{['한국어', 'English', '中文'].map((lang) => (
|
||||
<button
|
||||
key={lang}
|
||||
onClick={() => !isGenerating && setSelectedLang(lang)}
|
||||
disabled={isGenerating}
|
||||
onClick={() => !isGenerating && selectedType !== '배경음악' && setSelectedLang(lang)}
|
||||
disabled={isGenerating || selectedType === '배경음악'}
|
||||
className={`genre-btn ${selectedLang === lang ? 'active' : ''}`}
|
||||
>
|
||||
<span>{LANGUAGE_FLAGS[lang]}</span> {lang}
|
||||
@@ -495,8 +501,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
{['日本語', 'ไทย', 'Tiếng Việt'].map((lang) => (
|
||||
<button
|
||||
key={lang}
|
||||
onClick={() => !isGenerating && setSelectedLang(lang)}
|
||||
disabled={isGenerating}
|
||||
onClick={() => !isGenerating && selectedType !== '배경음악' && setSelectedLang(lang)}
|
||||
disabled={isGenerating || selectedType === '배경음악'}
|
||||
className={`genre-btn ${selectedLang === lang ? 'active' : ''}`}
|
||||
>
|
||||
<span>{LANGUAGE_FLAGS[lang]}</span> {lang}
|
||||
@@ -598,16 +604,28 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
|
||||
{/* Lyrics Display */}
|
||||
<div className="lyrics-display">
|
||||
{lyrics ? (
|
||||
<textarea
|
||||
value={lyrics}
|
||||
readOnly
|
||||
className="lyrics-textarea"
|
||||
placeholder={t('soundStudio.lyricsPlaceholder')}
|
||||
/>
|
||||
) : (
|
||||
{lyrics ? (() => {
|
||||
const lines = lyrics.split('\n').filter(l => l.trim());
|
||||
const size = Math.ceil(lines.length / 3);
|
||||
const outroLines = lines.slice(size * 2).slice(0, 2);
|
||||
const sections = [
|
||||
{ tag: '[Verse]', lines: lines.slice(0, size) },
|
||||
{ tag: '[Chorus]', lines: lines.slice(size, size * 2) },
|
||||
{ tag: '[Outro]', lines: outroLines },
|
||||
].filter(s => s.lines.length > 0);
|
||||
return (
|
||||
<div className="lyrics-paragraphs">
|
||||
{sections.map((section, i) => (
|
||||
<div key={i} className="lyrics-section">
|
||||
<span className="lyrics-tag">{section.tag}</span>
|
||||
<p className="lyrics-paragraph">{section.lines.join('\n')}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
})() : (
|
||||
<div className="lyrics-placeholder">
|
||||
{t('soundStudio.lyricsPlaceholder')}
|
||||
{selectedType === '배경음악' ? t('soundStudio.lyricsPlaceholderBGM') : t('soundStudio.lyricsPlaceholder')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user