Skip to main content

py_Audio2Face

Generate expressive facial animation from audio

Overview

This Python script leverages the headless mode of Audio2Face to generate animations for characters:

  • lip movement animations
  • face animations
  • emotions (new since 2023.2.0)
  • It provides methods to control the Audio2Face headless server and interact with it through a requests API.

Use cases:

  • Power your games and movies with expressive facial animations.
  • Create natural looking virtual avatars.
  • Generate animations for characters and export them as USD files for example for Maya or Unreal Engine 5.
  • Stream audio data to the Audio2Face server to generate animations in real-time. Use Live-Lynk to use them in UE5

Demo

Installation

Install the py_audio2face package using pip:

# With pip. Note: this version does not include the streaming feature
pip install py_audio2face
# Install also the streaming feature. This includes additional dependencies like grpcio and protobuf
pip install py_audio2face[streaming]
# Or install the latest version from GitHub to work with the newest version of Audio2Face
pip install git+https://github.com/SocAIty/py_audio2face.git

Modify the ROOT_DIR, DEFAULT_OUTPUT_DIR, and DEFAULT_AUDIO_STREAM_GRPC_PORT variables in the settings.py file as needed.

Prerequisites

Usage

First initialize Audio2Face instance:

import py_audio2face as pya2f
a2f = pya2f.Audio2Face()

Generate animation for audio files:

# Generate animation for a single audio file
a2f.audio2face_single(
   audio_file_path="path/to/audio/file.wav", #  path of the audio file you want to animate
   output_path="path/to/output/animation.usd",  # path where the animation file will be saved
   fps=60, # frames per second for the animation. Higher fps will result in smoother animations and longer processing time
   emotion_auto_detect=True  # automatically detect emotions in the audio file. If false the set emotion will be used
)

# Generate animation for an entire folder of audio files
a2f.audio2face_folder(input_folder="path/to/my/folder", output_folder='/output', fps=60)

Configure Emotions

The emotion mixin let's you control the strength of the emotions in the generated animation.

# Applies a preferred emotion even in emotion_auto_detect with update_settings=True
a2f.set_emotion(anger=0.9, disgust=0.5, fear=0.1, sadness=0.2, update_settings=True)
# Animate with a fixed set of emotione. 
animated = a2f.audio2face_single(test_audio_1,'emotion_full.usd', fps=24, emotion_auto_detect=False)
# Testing with expressive emotions. 
with_preferred_emotion_detect = a2f.audio2face_single(test_audio_1,'emotion_preset_detect.usd', fps=24, emotion_auto_detect=True)

You can also configure the emotion detection behaviour with the set_settings method.

a2f.a2e_set_settings(a2e_emotion_strength=0.5, a2e_smoothing_exp=0)

Stream audio to Audio2Face:

Instead of providing paths to the a2f headless server, you can stream the audio data directly to the server. This is useful if you want to generate animations in real-time, for a live stream or in a server setting.

For this example we use the media-toolkit to stream audio data. Install it with pip install media-toolkit[AudioFile]".

from media_toolkit import AudioFile
audio = AudioFile().from_file("path/to/audio/file.wav")
audio_stream = audio.to_stream()  # note: this can be any python generator that yields numpy arrays/bytes of audio data
a2f.stream_audio(audio_data, output_path="path/to/output/animation.usd", fps=60)

For streaming under the hood, a different scene with a streaming audio player is loaded in the init method. Then with gRPC requests, the audio data is streamed to the server.

Shutdown Audio2Face Server:

a2f.shutdown_a2f()

Related Projects

Why bother about recording audio files?

  • Convert text-to-speech with SpeechCraft. Use the natural sounding speech and feed it into audio2face.
  • Want sound natively like any other character? Use RVC to clone any voice. This sounds so real, you'll not notice the difference to a real one.
  • Create and animate realistic looking characters with MetaHuman and audio2face

Contribute

Any contribution is appreciated.

  • streaming: better clean-code for setting streaming mode. Especially with emotions, and default isntance.
  • streaming: upgrade to protobuf 5
  • streaming: allow streaming back of blendshapes or on the fly export
  • create working unit tests
  • Provide different characters not only mark.usd
  • Allow multiple generations / streams at the same time

Please raise an issue if you have any suggestions, feature requests or need help with the script.

Acknowledgements

Big thank you for the NVIDIA Team who made Audio2Face a great tool.

Metadata

Release files for py-audio2face 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-audio2face 0.1.3
File Size Uploaded Provenance Actions
py_audio2face-0.1.3.tar.gz 1.4 MB Without provenance Details for py_audio2face-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-audio2face 0.1.3
File Interpreter ABI Platform Actions
py_audio2face-0.1.3-py3-none-any.whl Python 3 none any Details for py_audio2face-0.1.3-py3-none-any.whl

Total release size: 2.7 MB

Release files / py_audio2face-0.1.3.tar.gz

Download URL py_audio2face-0.1.3.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
1a72b0add479bcb512f81cf8a30a4abd0eeeef1cb5a8bedb0c15ba03cc356cbe
BLAKE2b-256 checksum
How to use checksums
0056b419d242879c6a1e230cbc336676891f360e0b1a0d0328d4a71f7de9d8a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.11

Release files / py_audio2face-0.1.3-py3-none-any.whl

Download URL py_audio2face-0.1.3-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
09f18fbcb5925ee2faba34fd7b70df86a635a0cd0551be22c61a32076d88f0c7
BLAKE2b-256 checksum
How to use checksums
11a00195e2fa5254a19b617fc3353fdbb147d6f15240d6ef6ea6b4f8cbeedaaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.11

Security for py-audio2face 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page