TalkingHead

TalkingHead

实时3D虚拟人物交互与唇形同步系统

TalkingHead是一个开源的JavaScript类,用于创建具有实时语音和唇形同步功能的3D虚拟形象。该系统集成了Ready Player Me全身3D头像和Mixamo动画,并支持字幕显示。借助Google Cloud TTS实现文本转语音,TalkingHead还提供英语、芬兰语和立陶宛语的内置唇形同步。通过ThreeJS/WebGL进行3D渲染,开发者可以将其轻松集成到各种网页应用中。

TalkingHead3D头像实时对话唇形同步WebGLGithub开源项目

Talking Head (3D)

Demo Videos

VideoDescription
<span style="display: block; min-width:400px"><img src="images/screenshot4.jpg" width="400"/></span>I chat with Jenny and Harri. The close-up view allows you to evaluate the accuracy of lip-sync in both English and Finnish. Using GPT-3.5 and Microsoft text-to-speech.
<img src="images/screenshot5.jpg" width="400"/>A short demo of how AI can control the avatar's movements. Using OpenAI's function calling and Google TTS with the TalkingHead's built-in viseme generation.
<img src="images/screenshot6.jpg" width="400"/>Michael lip-syncs to two MP3 audio tracks using OpenAI's Whisper and TalkingHead's speakAudio method. He kicks things off with some casual talk, but then goes all out by trying to tackle an old Meat Loaf classic. 🤘 Keep rockin', Michael! 🎤😂
<img src="images/screenshot3.jpg" width="400"/>Julia and I showcase some of the features of the TalkingHead class and the test app including the settings, some poses and animations.

All the demo videos are real-time screen captures from a Chrome browser running the TalkingHead test web app without any post-processing.


Use Case Examples

Video/AppUse Case
<span style="display: block; min-width:400px"><img src="images/olivia.jpg" width="400"/></span>Video conferencing. A video conferencing solution with real-time transcription, contextual AI responses, and voice lip-sync. The app and demo, featuring Olivia, by namnm 👍
<img src="images/geminicompetition.jpg" width="400"/>Recycling Advisor 3D. Snap a photo and get local recycling advice from a talking avatar. My entry for the Gemini API Developer Competition.
<img src="images/evertrail.jpg" width="400"/>Live Twitch adventure. Evertrail is an infinite, real-time generated world where all of your choices shape the outcome. Video clip and the app by JPhilipp 👏👏
<img src="images/cliquevm.jpg" width="400"/>Quantum physics using a blackboard. David introduces us to the CHSH game and explores the mystery of quantum entanglement. For more information about the research project, see CliqueVM.
<img src="images/interactiveportfolio.jpg" width="400"/>Interactive Portfolio. Click the image to open the app, where you can interview the virtual persona of its developer, AkshatRastogi-1nC0re 👋

Introduction

Talking Head (3D) is a JavaScript class featuring a 3D avatar that can speak and lip-sync in real-time. The class supports Ready Player Me full-body 3D avatars (GLB), Mixamo animations (FBX), and subtitles. It also knows a set of emojis, which it can convert into facial expressions.

By default, the class uses Google Cloud TTS for text-to-speech and has a built-in lip-sync support for English, Finnish, and Lithuanian (beta). New lip-sync languages can be added by creating new lip-sync language modules. It is also possible to integrate the class with an external TTS service, such as Microsoft Azure Speech SDK or ElevenLabs WebSocket API.

The class uses ThreeJS / WebGL for 3D rendering.


Talking Head class

You can download the TalkingHead modules from releases (without dependencies). Alternatively, you can import all the needed modules from a CDN:

<script type="importmap"> { "imports": { "three": "https://cdn.jsdelivr.net/npm/three@0.161.0/build/three.module.js/+esm", "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.161.0/examples/jsm/", "talkinghead": "https://cdn.jsdelivr.net/gh/met4citizen/TalkingHead@1.2/modules/talkinghead.mjs" } } </script>

If you want to use the built-in Google TTS and lip-sync using Single Sign-On (SSO) functionality, give the class your TTS proxy endpoint and a function from which to obtain the JSON Web Token needed to use that proxy. Refer to Appendix B for one way to implement JWT SSO.

import { TalkingHead } from "talkinghead"; // Create the talking head avatar const nodeAvatar = document.getElementById('avatar'); const head = new TalkingHead( nodeAvatar, { ttsEndpoint: "/gtts/", jwtGet: jwtGet, lipsyncModules: ["en", "fi"] });

FOR HOBBYISTS: If you're just looking to experiment on your personal laptop without dealing with proxies, JSON Web Tokens, or Single Sign-On, take a look at the minimal code example. Simply download the file, add your Google TTS API key, and you'll have a basic web app template with a talking head.

The following table lists all the available options and their default values:

OptionDescription
jwsGetFunction to get the JSON Web Token (JWT). See Appendix B for more information.
ttsEndpointText-to-speech backend/endpoint/proxy implementing the Google Text-to-Speech API.
ttsApikeyIf you don't want to use a proxy or JWT, you can use Google TTS endpoint directly and provide your API key here. NOTE: I recommend that you don't use this in production and never put your API key in any client-side code.
ttsLangGoogle text-to-speech language. Default is "fi-FI".
ttsVoiceGoogle text-to-speech voice. Default is "fi-FI-Standard-A".
ttsRateGoogle text-to-speech rate in the range [0.25, 4.0]. Default is 0.95.
ttsPitchGoogle text-to-speech pitch in the range [-20.0, 20.0]. Default is 0.
ttsVolumeGoogle text-to-speech volume gain (in dB) in the range [-96.0, 16.0]. Default is 0.
ttsTrimStartTrim the viseme sequence start relative to the beginning of the audio (shift in milliseconds). Default is 0.
ttsTrimEndTrim the viseme sequence end relative to the end of the audio (shift in milliseconds). Default is 300.
lipsyncModulesLip-sync modules to load dynamically at start-up. Limiting the number of language modules improves the loading time and memory usage. Default is ["en", "fi", "lt"]. [≥v1.2]
lipsyncLangLip-sync language. Default is "fi".
pcmSampleRatePCM (signed 16bit little endian) sample rate used in speakAudio in Hz. Default is 22050.
modelRootThe root name of the armature. Default is Armature.
modelPixelRatioSets the device's pixel ratio. Default is 1.
modelFPSFrames per second. Note that actual frame rate will be a bit lower than the set value. Default is 30.
modelMovementFactorA factor in the range [0,1] limiting the avatar's upper body movement when standing. Default is 1. [≥v1.2]
cameraViewInitial view. Supported views are "full", "mid", "upper" and "head". Default is "full".
cameraDistanceCamera distance offset for initial view in meters. Default is 0.
cameraXCamera position offset in X direction in meters. Default is 0.
cameraYCamera position offset in Y direction in meters. Default is 0.
cameraRotateXCamera rotation offset in X direction in radians. Default is 0.
cameraRotateYCamera rotation offset in Y direction in radians. Default is 0.
cameraRotateEnableIf true, the user is allowed to rotate the 3D model. Default is true.
cameraPanEnableIf true, the user is allowed to pan the 3D model. Default is false.
cameraZoomEnableIf true, the user is allowed to zoom the 3D model. Default is false.
lightAmbientColorAmbient light color. The value can be a hexadecimal color or CSS-style string. Default is 0xffffff.
lightAmbientIntensityAmbient light intensity. Default is 2.
lightDirectColorDirection light color. The value can be a hexadecimal color or CSS-style string. Default is 0x8888aa.
lightDirectIntensityDirection light intensity. Default is 30.
lightDirectPhiDirection light phi angle. Default is 0.1.
lightDirectThetaDirection light theta angle. Default is 2.
lightSpotColorSpot light color. The value can be a hexadecimal color or CSS-style string. Default is 0x3388ff.
lightSpotIntensitySpot light intensity. Default is 0.
lightSpotPhiSpot light phi angle. Default is 0.1.
lightSpotThetaSpot light theta angle. Default is 4.
lightSpotDispersionSpot light dispersion. Default is 1.
avatarMoodThe mood of the avatar. Supported moods: "neutral", "happy", "angry", "sad", "fear", "disgust", "love", "sleep". Default is "neutral".
avatarMuteMute the avatar. This can be helpful option if you want to output subtitles without audio and lip-sync. Default is false.
markedOptionsOptions for Marked markdown parser. Default is { mangle:false, headerIds:false, breaks: true }.
statsNodeParent DOM element for the three.js stats display. If null, don't use. Default is null.
statsStyleCSS style for the stats element. If null, use the three.js default style. Default is null.

Once the instance has been created, you can load and display your avatar. Refer to Appendix A for how to make your avatar:

// Load and show the avatar try { await head.showAvatar( { url: './avatars/brunette.glb', body: 'F', avatarMood: 'neutral', ttsLang: "en-GB", ttsVoice: "en-GB-Standard-A", lipsyncLang: 'en' }); } catch (error) { console.log(error); }

An example of how to make the avatar speak the text on input text when the button speak is clicked:

// Speak 'text' when the button 'speak' is clicked const nodeSpeak = document.getElementById('speak'); nodeSpeak.addEventListener('click', function () { try { const text = document.getElementById('text').value; if ( text ) { head.speakText( text ); } } catch (error) { console.log(error); } });

The following table lists some of the key methods. See the source code for the rest:

MethodDescription
showAvatar(avatar, [onprogress=null])Load and show the specified avatar. The avatar object must include the url for GLB file. Optional properties are body for either male M or female F body form, lipsyncLang, ttsLang, ttsVoice, ttsRate, ttsPitch, ttsVolume, avatarMood and avatarMute.
setView(view, [opt])Set view. Supported views are "full", "mid", "upper" and "head". The opt object can be used to set cameraDistance, cameraX, cameraY, cameraRotateX, cameraRotateY.
setLighting(opt)Change lighting settings. The opt object can be used to set lightAmbientColor, lightAmbientIntensity, lightDirectColor, lightDirectIntensity, lightDirectPhi, lightDirectTheta, lightSpotColor, lightSpotIntensity, lightSpotPhi, lightSpotTheta, lightSpotDispersion.
speakText(text, [opt={}], [onsubtitles=null], [excludes=[]])Add the text string to the speech queue. The text can contain face emojis. Options opt can be used to set text-specific lipsyncLang, ttsLang, ttsVoice, ttsRate, ttsPitch, ttsVolume, avatarMood, avatarMute. Optional callback function onsubtitles is called whenever a new subtitle is to be written with the parameter of the added string. The optional excludes is an array of [start,end] indices to be excluded from audio but to be included in the subtitles.
speakAudio(audio, [opt={}], [onsubtitles=null])Add a new audio object to the speech queue. In audio object, property audio is either AudioBuffer or an array of PCM 16bit LE audio chunks. Property words is an array of words, wtimes is an array of corresponding starting times in milliseconds, and wdurations an array of durations in milliseconds. If the Oculus viseme IDs are know, they can be given in optional visemes, vtimes and vdurations arrays. The object also supports optional timed callbacks using markers and mtimes. The opt object can be used to set text-specific lipsyncLang.
speakEmoji(e)Add an emoji e to the speech queue.
speakBreak(t)Add a break of t milliseconds to the speech queue.
speakMarker(onmarker)Add a marker to the speech queue. The callback function onmarker is called when the queue processes the event.
lookAt(x,y,t)Make the avatar's head turn to look at the screen position (x,y) for t milliseconds.
lookAtCamera(t)Make the avatar's head turn to look at the camera for t milliseconds.
setMood(mood)Set avatar mood.
playBackgroundAudio(url)Play background audio such as ambient sounds/music in a loop.
stopBackgroundAudio()Stop playing the background audio.
setMixerGain(speech, background)The amount of gain for speech and background audio (see Web Audio API / GainNode for more information). Default value is 1.
playAnimation(url, [onprogress=null], [dur=10], [ndx=0], [scale=0.01])Play Mixamo animation file for dur seconds, but full rounds and at least once. If the FBX file includes several animations, the parameter ndx specifies the index. Since Mixamo rigs have a scale 100 and RPM a scale 1, the scale factor can be used to scale the positions.
stopAnimation()Stop the current animation started by playAnimation.
playPose(url, [onprogress=null], [dur=5], [ndx=0], [scale=0.01])Play the initial pose of a Mixamo animation file for dur seconds. If the FBX file includes several animations, the parameter ndx specifies the index. Since Mixamo rigs have a scale 100 and RPM a scale 1, the scale factor can be used to scale the positions.
stopPose()Stop the current pose started by playPose.
playGesture(name, [dur=3], [mirror=false], [ms=1000])Play a named hand gesture and/or animated emoji for dur seconds with the ms transition time. The available hand gestures are handup, index, ok, thumbup, thumbdown, side, shrug. By default, hand gestures are done with the left hand. If you want the right handed version, set mirror to true. You can also use playGesture to play emojis. See Appendix D for more details. [≥v1.2]
stopGesture([ms=1000])Stop the gesture with ms transition time. [≥v1.2]
startStart/re-start the Talking Head animation loop.
stopStop the Talking Head animation loop.

The class has been tested on the latest Chrome, Firefox, Safari, and Edge desktop browsers, as well as on iPad.


The index.html Test

编辑推荐精选

扣子-AI办公

扣子-AI办公

职场AI,就用扣子

AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!

堆友

堆友

多风格AI绘画神器

堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

图像生成AI工具AI反应堆AI工具箱AI绘画GOAI艺术字堆友相机AI图像热门
码上飞

码上飞

零代码AI应用开发平台

零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

下拉加载更多