Search code examples
aframegltf

How to make the 3D model avatar talking when my voice is detected on a-frame


What I want is that on a-frame, when I talk, my 3D model avatar is also being made talking.

Following this guide, https://aframe.io/docs/1.1.0/introduction/models.html#animating-models, I created 3D model avatar with this resource, https://sketchfab.com/3d-models/bake-talking3-e715ab67be934a108d0a952d90c07210

But this gltf 3D model is talking all the time. I need interactive 3D model talking whenever I talk.

Let's assume my voice detection is already implemented.

Can anyone answer this, please?


Solution

  • The animation-mixer component has two methods that should help

    • playAction() which will play the
    • stopAction() which will stop the

    Let's assume my voice detection is already implemented.

    Then Your code could look like this:

    const modelEntity = document.querySelector("[gltf-model]")
    const animationComponent = modelEntity.components["animation-mixer"]
    mySpeechRecognition.onspeechstart = function() {
       animationComponent.playAction();
    }
    
    mySpeechRecognition.onspeechend= function() {
       animationComponent.stopAction();
    }
    

    Something like what I did in this glitch. Green plays, red stops. Click on the fish to check out the source.