首页 > 解决方案 > 如何在框架上检测到我的声音时让 3D 模型头像说话

问题描述

我想要的是在一个框架上,当我说话时,我的 3D 模型头像也正在说话。

按照本指南https://aframe.io/docs/1.1.0/introduction/models.html#animating-models,我使用此资源创建了 3D 模型头像https://sketchfab.com/3d-models/bake -talking3-e715ab67be934a108d0a952d90c07210

但是这个 gltf 3D 模型一直在说话。每当我说话时,我都需要交互式 3D 模型说话。

假设我的语音检测已经实现。

请问有人能回答这个吗?

标签: aframegltf

解决方案


animation-mixer组件有两种方法可以帮助

  • playAction() 将播放
  • stopAction() 将停止

假设我的语音检测已经实现。

然后您的代码可能如下所示:

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

mySpeechRecognition.onspeechend= function() {
   animationComponent.stopAction();
}

就像我在这个故障中所做的那样。绿色播放,红色停止。单击鱼以查看来源。


推荐阅读