3b1b-manim/manimlib/utils/sounds.py

41 lines
749 B
Python
Raw Normal View History

import os
from manimlib.utils.file_ops import find_file
2021-01-23 11:02:02 -08:00
from manimlib.utils.directories import get_sound_dir
def play_chord(*nums):
commands = [
"play",
"-n",
"-c1",
"--no-show-progress",
"synth",
] + [
"sin %-" + str(num)
for num in nums
] + [
"fade h 0.5 1 0.5",
">",
os.devnull
]
try:
os.system(" ".join(commands))
2021-01-23 11:02:02 -08:00
except Exception:
pass
def play_error_sound():
play_chord(11, 8, 6, 1)
def play_finish_sound():
play_chord(12, 9, 5, 2)
2019-01-24 22:24:01 -08:00
def get_full_sound_file_path(sound_file_name):
return find_file(
2019-01-24 22:24:01 -08:00
sound_file_name,
2021-01-23 11:02:02 -08:00
directories=[get_sound_dir()],
2019-01-24 22:24:01 -08:00
extensions=[".wav", ".mp3"]
)