(event)
| 54 | } |
| 55 | |
| 56 | async function generateSound(event) { |
| 57 | event.preventDefault(); |
| 58 | |
| 59 | const isSimple = document.getElementById('mode-simple').checked; |
| 60 | if (isSimple) { |
| 61 | const text = document.getElementById('text').value.trim(); |
| 62 | if (!text) { |
| 63 | showNotification('error', 'Please enter text (description)'); |
| 64 | return; |
| 65 | } |
| 66 | } else { |
| 67 | // Advanced mode: only check caption and lyrics (text field is hidden and not used) |
| 68 | const caption = document.getElementById('caption').value.trim(); |
| 69 | const lyrics = document.getElementById('lyrics').value.trim(); |
| 70 | if (!caption && !lyrics) { |
| 71 | showNotification('error', 'Please enter at least caption or lyrics'); |
| 72 | return; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | const loader = document.getElementById('loader'); |
| 77 | const resultDiv = document.getElementById('result'); |
| 78 | const generateBtn = document.getElementById('generate-btn'); |
| 79 | |
| 80 | loader.style.display = 'block'; |
| 81 | generateBtn.disabled = true; |
| 82 | resultDiv.innerHTML = '<p class="text-[var(--color-text-secondary)] italic">Generating sound...</p>'; |
| 83 | |
| 84 | try { |
| 85 | const response = await fetch('v1/sound-generation', { |
| 86 | method: 'POST', |
| 87 | headers: { 'Content-Type': 'application/json' }, |
| 88 | body: JSON.stringify(buildRequestBody()), |
| 89 | }); |
| 90 | |
| 91 | if (!response.ok) { |
| 92 | let errMsg = 'Request failed'; |
| 93 | const ct = response.headers.get('content-type'); |
| 94 | if (ct && ct.indexOf('application/json') !== -1) { |
| 95 | const json = await response.json(); |
| 96 | if (json && json.error && json.error.message) errMsg = json.error.message; |
| 97 | } |
| 98 | resultDiv.innerHTML = '<div class="text-red-400 flex items-center gap-2"><i class="fas fa-circle-exclamation"></i> ' + errMsg + '</div>'; |
| 99 | showNotification('error', 'Failed to generate sound'); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | const blob = await response.blob(); |
| 104 | const audioUrl = window.URL.createObjectURL(blob); |
| 105 | |
| 106 | const wrap = document.createElement('div'); |
| 107 | wrap.className = 'flex flex-col items-center gap-4 w-full'; |
| 108 | |
| 109 | const audio = document.createElement('audio'); |
| 110 | audio.controls = true; |
| 111 | audio.src = audioUrl; |
| 112 | audio.className = 'w-full max-w-md'; |
| 113 |
nothing calls this directly
no test coverage detected