citron2010's Forum Posts

  • ...using 'Set response binary' has no effect once the AJAX request has completed. You must use that before sending the request for it to load in to the Binary Data object automatically when the request completes.

    Argh! Sorry - didn't read the manual thoroughly - it's working now that I've set that before the request. Thanks everyone - I now have a fully working native event sheet solution!

  • Sorry - should have screenshot more - I only run those events on the click of a button which is only enabled once the AJAX request had completed. I'll try to adapt my project to use the free version of Eleven Labs so anyone can try.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm using a paid Eleven Labs account.

    The JavaScript above works fine - sending the request, playing the response in JS, passing the URL of the response to a global variable, then in the event sheet, setting the Audio plugin's "Add remote URL" to that var and playing it (so I can insert effects).

    This is everything I need, but I was trying to do it all in event sheets, but something's not working in the events in the screenshot above. If I download AJAX.LastData, I see stuff like this in the header:

    ID3 #TSSE  Lavf60.16.100

    But VLC won't play it and presumably also why I get "EncodingError: Unable to decode audio data" when trying to play it in the event sheet using the actions in the screenshot.

  • I was just trying that to see what happened because:

    Also results in "EncodingError: Unable to decode audio data"

  • 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);
    });
  • Unfortunately they don't provide a URL - just audio to download in one of a myriad of formats! It's this API:

    elevenlabs.io/docs/api-reference/text-to-speech/convert

    I'll keep experimenting, because it IS returning something!

  • Hi,

    I’m trying to use Eleven Labs text-to-speech API to generate and then play MP3s.

    I request in their default format – “output_format=mp3_44100_128” using an AJAX request.

    But I’m not sure how to play it.

    I’m assuming I need to pass it to a Binary Data object first and have tried:

    • BinaryData – set from base64 (this produces no data)
    • AJAX – Set response binary -> Destination = BinaryData (also produces no data)
    • BinaryData – set from text (this does produce data)

    (If I download this via Browser – Invoke Download for string = BinaryData.GetAllText, MIME type = “audio/mpeg), it downloads something, but it won’t play)

    I’ve then tried:

    • Audio – Add remote URL = BinaryData (type = audio/mpeg) and added a tag
    • Audio – play tag

    But this returns:

    Failed to load audio 'blob:https://preview.construct.net/<some UID>': EncodingError: Unable to decode audio data

    Any ideas? I don’t really want to use JavaScript but importantly, I need to be able to use C3’s effects – specifically the audio analyser so I can animate a sprite based on the audio’s level.

  • I'm doing something very similar and agree with dop2000 that having slightly higher gravity would look better.

    But the other thing I did was move the image point that I'm applying the force too so that it's off centre, so when the force is applied, the parts rotate more.

  • It's hard to diagnose from just those screenshots, but one way to troubleshoot would be to write the animation's name, frame & position to an on-screen text box every tick. Then record the issue and play it back in slow motion to see exactly what's happening. Or you could use the debugger to step through the animation and view those parameters in the inspector.

  • Do you have details of this bug? Sounds rather worrying!

  • On a similar note, is there any way to change the column widths (i.e. the event or actions columns)?

  • Don't see why the physics behaviour couldn't be used for this - but you would need to experiment with the gravity and falling objects' elasticity and possibly their density, friction, & linear/angular damping.

  • You can't do this using "On key pressed" but you can using "Is key down".

  • See the "Using BBCode" section in the manual:

    construct.net/en/make-games/manuals/construct-3/plugin-reference/text

    There's also a linked example project.