That’s what I’ve tried – both:
- AJAX Set Response to BinaryData
- BinaryData Set buffer to UTF-8 text AJAX.LastData
(Which I believe are equivalent)
If I then download it, I can see some relevant headers when opened in a text editor, but can’t play it in e.g. VLC. And Audio –> Add remote URL = BinaryData.GetURL -> Play returns “EncodingError: Unable to decode audio data”
I’ve been working with ChatGPT on this and it gave me some JavaScript which sends the request, successfully plays the response and sets a var to the URL of the response. When that URL is then used in Audio – Add remote URL, it DOES work.
My ultimate aim is to use the Audio Analyser effect to animate a sprite (to sync lip animation), so this approach works, but agree that it _should_ work using native C3 events.
This is ChatGPT's JavaScript:
fetch("https://api.elevenlabs.io/v1/text-to-speech/fexRy0lZ3HSLmYNrlI0v?output_format=mp3_44100_128", {
method: "POST",
headers: {
"xi-api-key": "<my_secret_key",
"Content-Type": "application/json"
},
body: JSON.stringify({
text: "Construct 3 Rocks.",
model_id: "eleven_multilingual_v2"
})
})
.then(response => response.blob())
.then(blob => {
const audioURL = URL.createObjectURL(blob);
// OPTION A: Play using JS
const audio = new Audio(audioURL);
audio.play().then(() => console.log("Audio is playing")).catch(console.error);
// OPTION B: Pass to Construct's Audio plugin
runtime.globalVars.AudioDataURL = audioURL; // You must create this global text variable
})
.catch(err => {
console.error("Failed to fetch ElevenLabs audio:", err);
});