{"id":4271,"date":"2023-04-07T10:05:44","date_gmt":"2023-04-07T01:05:44","guid":{"rendered":"https:\/\/blog.criware.com\/?p=4271"},"modified":"2024-05-20T15:07:47","modified_gmt":"2024-05-20T06:07:47","slug":"using-adx-lipsync-in-unity","status":"publish","type":"post","link":"https:\/\/blog.criware.com\/index.php\/2023\/04\/07\/using-adx-lipsync-in-unity\/","title":{"rendered":"Using ADX LipSync in Unity"},"content":{"rendered":"<p>In our <a href=\"https:\/\/blog.criware.com\/index.php\/2023\/04\/05\/introduction-to-adx-lipsync-tools\/\">previous post<\/a> we described the offline generation of mouth patterns by analyzing speech data with CriLipsMake, and how artists can use them to create facial animation in their tools.<\/p>\n<p>This time, we will see how such mouth patterns can also be obtained by analyzing audio played in real-time, by using the ADX LipSync Library in Unity.<\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Unity Plug-in<\/h2>\n<p>The easiest way to use ADX LipSync in Unity is via the extension package provided with the CRIWARE Unity Plugin. Its location is:<\/p>\n<p>\\expansion\\cri_adx_lipsync\\unity\\plugin\\cri_adxlipsync_unity_plugin.unitypackage.<\/p>\n<p>The plugin operation is simple and consists in connecting a sound source \u2013 via a <em>CriAtomSource<\/em> \u2013 to a dedicated <em>CriLipsDeformer<\/em> component. This component analyzes the sound in real-time and controls the mouth movements of a character during audio playback.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4275\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/01-Adxlipsync-library-flow.png\" alt=\"01 Adxlipsync library flow\" width=\"1296\" height=\"324\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/01-Adxlipsync-library-flow.png 1296w, https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/01-Adxlipsync-library-flow-300x75.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/01-Adxlipsync-library-flow-768x192.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/01-Adxlipsync-library-flow-1024x256.png 1024w\" sizes=\"auto, (max-width: 1296px) 100vw, 1296px\" \/><\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Character model preparation<\/h2>\n<p>The character model has to be prepared in advance in order for its mouth shape to be controllable from the ADX LipSync data. Blend shapes created in an external tool such as Maya or Blender can be used, as well as those made directly with the Unity Animator functions.<\/p>\n<p>Once your model is ready, it can be imported directly into your scene. For instance, the character model used for this post has nine blend shapes corresponding to the following two mouth-shaped morph targets generated by ADX LipSync:<\/p>\n<ul>\n<li>Vertical opening, side opening, side closing, tongue height.<\/li>\n<li>5 Japanese vowels A, I, U, E, O.<\/li>\n<\/ul>\n<p>This is what the blend shapes look like individually:<\/p>\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4271-1\" width=\"800\" height=\"450\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/Video_01_BlendShapes.mp4?_=1\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/Video_01_BlendShapes.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/Video_01_BlendShapes.mp4<\/a><\/video><\/div>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Simple implementation<\/h2>\n<p>Here is a simple way to control the motion of a character\u2019s mouth with ADX LipSync:<\/p>\n<ul>\n<li>In the <em>Scene<\/em>, create a new <em>Game Object<\/em>, with a <em>CRI Atom Source<\/em> component.<\/li>\n<li>Fill in the <em>Cue Sheet<\/em> and <em>Cue Name<\/em> properties of the component, and enable <em>Play On Start<\/em>.<\/li>\n<li>Then, under the <em>CRI Atom Source<\/em>, add a <em>CriLipsDeformerForAtomSource<\/em> component.<\/li>\n<\/ul>\n<div style=\"text-align:center;\">\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/02-CriLipsDeformer-component.png\" alt=\"02 CriLipsDeformer component\" width=\"565\" height=\"233\" class=\"alignnone size-full wp-image-4279\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/02-CriLipsDeformer-component.png 565w, https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/02-CriLipsDeformer-component-300x124.png 300w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/>\n<\/div>\n<p><\/p>\n<p>The properties of the component are as following:<\/p>\n<ul>\n<li><em>CriAtomSource:<\/em> Select the CriAtomSource that will provide the audio to be analyzed.<\/li>\n<li><em>Morph Target:<\/em> Choose the type of blend shape used (Unity Animator or standard blend shape) between the two mouth-shaped morph targets (Width\/Height or Japanese vowels). The options are:\n<ul>\n<li><em>CriLipsMorphAnimatorJapaneseVowel<\/em><\/li>\n<li><em>CriLipsMorphAnimatorWidthHeight<\/em><\/li>\n<li><em>CriLipsMorphBlendShapeJapaneseVowel<\/em><\/li>\n<li><em>CriLipsMorphBlendShapeWidthHeight<\/em><\/li>\n<\/ul>\n<\/li>\n<li><em>Target:<\/em> Select the character model you want to control.<\/li>\n<li><em>Index <\/em>or<em> Hash: <\/em>Way to link the morph targets to the character\u2019s blend shape.<\/li>\n<li><em>SilenceThreshold(dB): <\/em>Threshold value below which the signal is considered silent.<\/li>\n<li><em>SamplingRate(Hz):<\/em> Sampling frequency of the audio data to be analyzed.<\/li>\n<\/ul>\n<p>Launch the scene, and you should now see the character&#8217;s lips move in sync with the audio being played.<\/p>\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-4271-2\" width=\"800\" height=\"450\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/Video_02_LipSyncDemo.mp4?_=2\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/Video_02_LipSyncDemo.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2023\/04\/Video_02_LipSyncDemo.mp4<\/a><\/video><\/div>\n<p><\/p>\n<p>Because the ADX LipSync library analyzes audio in real time, the CPU load can become quite high when multiple audio streams are processed simultaneously. It is therefore recommended to perform lip-sync on a maximum of two characters at a time. Of course, the CriLipsAtomAnalyzer, which performs the analysis, can be dynamically attached and detached from a CriAtomExPlayer, which allows to work around this limitation.<\/p>\n<p>Now you have all the tools you need to create high-quality facial animation and lip-sync for your game, either offline or in real time!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our previous post we described the offline generation of mouth patterns by analyzing speech data with CriLipsMake, and how<\/p>\n","protected":false},"author":2,"featured_media":5428,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[16,7],"tags":[],"class_list":["post-4271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lipsync","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/4271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/comments?post=4271"}],"version-history":[{"count":12,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/4271\/revisions"}],"predecessor-version":[{"id":4297,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/4271\/revisions\/4297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media\/5428"}],"wp:attachment":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media?parent=4271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/categories?post=4271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/tags?post=4271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}