diff --git a/uncloseai.js b/uncloseai.js index 985aa75..27f5fca 100644 --- a/uncloseai.js +++ b/uncloseai.js @@ -693,6 +693,54 @@ async function integrateMegafarceResponse(response) { chatBox.appendChild(systemMessage); chatBox.scrollTop = chatBox.scrollHeight; + + // Add Generate TTS button for the uploaded content + const generateTTSButton = document.createElement('button'); + generateTTSButton.textContent = 'Generate TTS for Uploaded Content'; + let ttsAudio = null; + let ttsBlob = null; + let isPaused = false; + + generateTTSButton.onclick = async () => { + if (!ttsAudio) { + generateTTSButton.textContent = 'Processing...'; + generateTTSButton.disabled = true; // Disable button while processing + try { + const result = await speakText(content); + ttsAudio = result.audio; + ttsBlob = result.blob; + generateTTSButton.textContent = 'Pause TTS'; + generateTTSButton.disabled = false; // Re-enable button after processing + ttsAudio.play(); + + // Add download button for the TTS audio + const downloadButton = document.createElement('button'); + downloadButton.textContent = 'Download MP3'; + downloadButton.onclick = () => { + const a = document.createElement('a'); + a.href = URL.createObjectURL(ttsBlob); + a.download = 'uploaded-content.mp3'; + a.click(); + }; + chatBox.appendChild(downloadButton); + } catch (error) { + console.error('Error generating TTS:', error); + alert('Failed to generate TTS for the uploaded content.'); + generateTTSButton.textContent = 'Generate TTS for Uploaded Content'; + generateTTSButton.disabled = false; + } + } else { + if (isPaused) { + ttsAudio.play(); + generateTTSButton.textContent = 'Pause TTS'; + } else { + ttsAudio.pause(); + generateTTSButton.textContent = 'Play TTS'; + } + isPaused = !isPaused; + } + }; + chatBox.appendChild(generateTTSButton); } // Initialize the chat interface