Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added gain to Scene.add_sound

Grant Sandersoneb355fc7a196
diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py
index 66f4dc5ea..8be55952c 100644
--- a/manimlib/scene/scene.py
+++ b/manimlib/scene/scene.py
@@ -568,9 +568,9 @@ class Scene(Container):
for frame in frames:
self.file_writer.write_frame(frame)
- def add_sound(self, sound_file, time_offset=0):
+ def add_sound(self, sound_file, time_offset=0, gain=0):
time = self.get_time() + time_offset
- self.file_writer.add_sound(sound_file, time)
+ self.file_writer.add_sound(sound_file, time, gain)
def show_frame(self):
self.update_frame(ignore_skipping=True)
diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py
index 7337748ed..9ca5664f8 100644
--- a/manimlib/scene/scene_file_writer.py
+++ b/manimlib/scene/scene_file_writer.py
@@ -119,7 +119,7 @@ class SceneFileWriter(object):
def create_audio_segment(self):
self.audio_segment = AudioSegment.silent()
- def add_audio_segment(self, new_segment, time=None):
+ def add_audio_segment(self, new_segment, time=None, gain=0):
if not self.includes_sound:
self.includes_sound = True
self.create_audio_segment()
@@ -138,13 +138,15 @@ class SceneFileWriter(object):
crossfade=0,
)
self.audio_segment = segment.overlay(
- new_segment, position=int(1000 * time)
+ new_segment,
+ position=int(1000 * time),
+ gain_during_overlay=gain,
)
- def add_sound(self, sound_file, time):
+ def add_sound(self, sound_file, time, gain=0):
file_path = get_full_sound_file_path(sound_file)
new_segment = AudioSegment.from_file(file_path)
- self.add_audio_segment(new_segment, time)
+ self.add_audio_segment(new_segment, time, gain)
# Writers
def begin_animation(self, allow_write=False):