Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Bugfix: make Scene.add_sound work again (when running with --disable_caching) (#907)

Benjamin Hackl698921a54026
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index bc8b6a2dc..617ffba23 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -881,5 +881,5 @@ class Scene(Container):
"""
if self.renderer.skip_animations:
return
- time = self.time + time_offset
+ time = self.renderer.time + time_offset
self.renderer.file_writer.add_sound(sound_file, time, gain, **kwargs)
diff --git a/tests/test_sound.py b/tests/test_sound.py
new file mode 100644
index 000000000..d7614eca6
--- /dev/null
+++ b/tests/test_sound.py
@@ -0,0 +1,20 @@
+import os, struct, wave
+
+from manim import Scene
+
+
+def test_add_sound():
+ # create sound file
+ f = wave.open("noise.wav", "w")
+ f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
+ for _ in range(22050): # half a second of sound
+ packed_value = struct.pack("h", 14242)
+ f.writeframes(packed_value)
+ f.writeframes(packed_value)
+
+ f.close()
+
+ scene = Scene()
+ scene.add_sound("noise.wav")
+
+ os.remove("noise.wav")