This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| animatronic_mouth.py | |
| This script animates a motorized mouth on a Raspberry Pi GPIO pin so that it | |
| appears to be speaking alongside the audio on the specified PulseAudio source | |
| (which usually should be a sink's monitor). | |
| Find PA_SOURCE with `pactl list` and look for a monitor device that corresponds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_aspect(width: int, height: int) -> str: | |
| def gcd(a, b): | |
| """The GCD (greatest common divisor) is the highest number that evenly divides both width and height.""" | |
| return a if b == 0 else gcd(b, a % b) | |
| r = gcd(width, height) | |
| x = int(width / r) | |
| y = int(height / r) | |
| return f"{x}:{y}" |