Project Icon

TalkingHead

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

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

Talking Head (3D)

Demo Videos

VideoDescription
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.
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.
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! 🎤😂
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
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 👍
Recycling Advisor 3D. Snap a photo and get local recycling advice from a talking avatar. My entry for the Gemini API Developer Competition.
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 👏👏
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.
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

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

白日梦AI

白日梦AI提供专注于AI视频生成的多样化功能,包括文生视频、动态画面和形象生成等,帮助用户快速上手,创造专业级内容。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

讯飞绘镜

讯飞绘镜是一个支持从创意到完整视频创作的智能平台,用户可以快速生成视频素材并创作独特的音乐视频和故事。平台提供多样化的主题和精选作品,帮助用户探索创意灵感。

Project Cover

讯飞文书

讯飞文书依托讯飞星火大模型,为文书写作者提供从素材筹备到稿件撰写及审稿的全程支持。通过录音智记和以稿写稿等功能,满足事务性工作的高频需求,帮助撰稿人节省精力,提高效率,优化工作与生活。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

AIWritePaper论文写作

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

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号