<input type="text" id="userId" value="user-123">
<input type="text" id="speechUrl" value="https://example.com/speech.mp3">
<button id="playButton">Play Voice</button>
<audio id="audioPlayer" controls></audio>
<script>
async function getVoiceAudio() {
const userId = document.getElementById("userId").value;
const speechUrl = document.getElementById("speechUrl").value;
const response = await fetch("https://api.soundverse.ai/v1/assistant/voice", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer your_api_key_here"
},
body: JSON.stringify({ speech_url: speechUrl }),
});
if (!response.ok || !response.body) {
throw new Error("Failed to fetch audio");
}
const reader = response.body.getReader();
const chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}
const blob = new Blob(chunks, { type: "audio/mpeg" });
const url = URL.createObjectURL(blob);
const audio = document.getElementById("audioPlayer");
audio.src = url;
audio.play();
}
document.getElementById("playButton").addEventListener("click", getVoiceAudio);
</script>