TTS for user uploaded content for uncloseai.js
modified: uncloseai.js
This commit is contained in:
parent
a833cb5699
commit
a245e48c20
1 changed files with 48 additions and 0 deletions
48
uncloseai.js
48
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue