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

编辑推荐精选

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

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

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

Hunyuan3D-2

Hunyuan3D-2

高分辨率纹理 3D 资产生成

Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。

3FS

3FS

一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。

3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。

下拉加载更多