# How to trigger an animation based on realtime audio

**URL:** <https://discourse.processing.org/t/how-to-trigger-an-animation-based-on-realtime-audio/21066>\
**Category:** Libraries\
**Created:** [May 19, 2020, 5:37pm UTC](https://discourse.processing.org/t/how-to-trigger-an-animation-based-on-realtime-audio/21066 "2020-05-19T17:37:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkk16](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rkk16](https://discourse.processing.org/u/rkk16)\
**Post date:** [May 19, 2020, 5:37pm UTC](https://discourse.processing.org/t/how-to-trigger-an-animation-based-on-realtime-audio/21066/1 "2020-05-19T17:37:42Z")

</div>

Trying to build a face with moving lips as someone speaks realtime, any idea how to use audio as a trigger like if(mousePressed) - instead being if a threshold of amplitude is received, then perform {block of code}?

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 19, 2020, 9:23pm UTC](https://discourse.processing.org/t/how-to-trigger-an-animation-based-on-realtime-audio/21066/2 "2020-05-19T21:23:06Z")

</div>

Hi,

Welcome to the Processing Community! 🙂

You can take a look at the [Processing Sound library](https://processing.org/reference/libraries/sound/index.html) to manage sound (input, output, audio processing, analyse…) specially the `Amplitude` class :

- [https://processing.org/reference/libraries/sound/Amplitude.html](https://processing.org/reference/libraries/sound/Amplitude.html)

---

<div class="post-metadata">

**Author:** ![rkk16](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@rkk16](https://discourse.processing.org/u/rkk16)\
**Post date:** [May 20, 2020, 6:06am UTC](https://discourse.processing.org/t/how-to-trigger-an-animation-based-on-realtime-audio/21066/3 "2020-05-20T06:06:19Z")

</div>

Thank you! I’m new to processing but it seems extremely useful. Any idea on how to incorporate OpenCV? I want my animated face to imitate the expressions made by a person in front of a camera.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 26, 2020, 8:23am UTC](https://discourse.processing.org/t/how-to-trigger-an-animation-based-on-realtime-audio/21066/4 "2020-05-26T08:23:52Z")

</div>

Hi,

I don’t think that the OpenCV library can detect eyes and facial elements but it can detect a whole face :

- [https://github.com/atduskgreg/opencv-processing#facedetection](https://github.com/atduskgreg/opencv-processing#facedetection)

But a solution is to use custom cascades (which are files to detect a certain pattern) :

- [https://forum.processing.org/one/topic/opencv-detect-custom-cascades.html](https://forum.processing.org/one/topic/opencv-detect-custom-cascades.html)
