mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Add play_sound
This commit is contained in:
parent
ef7dbc09ad
commit
edf883f229
1 changed files with 28 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import threading
|
||||||
|
import platform
|
||||||
|
|
||||||
from manimlib.utils.directories import get_sound_dir
|
from manimlib.utils.directories import get_sound_dir
|
||||||
from manimlib.utils.file_ops import find_file
|
from manimlib.utils.file_ops import find_file
|
||||||
|
|
||||||
|
@ -10,3 +14,27 @@ def get_full_sound_file_path(sound_file_name: str) -> str:
|
||||||
directories=[get_sound_dir()],
|
directories=[get_sound_dir()],
|
||||||
extensions=[".wav", ".mp3", ""]
|
extensions=[".wav", ".mp3", ""]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def play_sound(sound_file):
|
||||||
|
"""Play a sound file using the system's audio player"""
|
||||||
|
full_path = get_full_sound_file_path(sound_file)
|
||||||
|
system = platform.system()
|
||||||
|
|
||||||
|
if system == "Windows":
|
||||||
|
# Windows
|
||||||
|
subprocess.Popen(
|
||||||
|
["powershell", "-c", f"(New-Object Media.SoundPlayer '{full_path}').PlaySync()"],
|
||||||
|
shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
elif system == "Darwin":
|
||||||
|
# macOS
|
||||||
|
subprocess.Popen(
|
||||||
|
["afplay", full_path],
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
subprocess.Popen(
|
||||||
|
["aplay", full_path],
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue