ManimCommunity / manim-voiceover

Manim plugin for all things voiceover
https://voiceover.manim.community/en/stable
MIT License
168 stars 22 forks source link

Automatic stretching of animations to voiceover duration #37

Open pesho-ivanov opened 1 year ago

pesho-ivanov commented 1 year ago

Description of proposed feature

I suggest to proportionally stretch all animations to match their voiceover duration.

How can the new feature be used?

It can be fiddly to manually tune animation durations. In order to eliminate the additional complication of the voiceover duration, this can be automatized.

Additional comments

I reimplemented the voiceover generator to do everything behind the scenes with no additional complexity: https://github.com/pesho-ivanov/thesis-manim

I have successfully used my implementation but it is probably not complete. Will be cool if it can be integrated into manim-voiceover or even manim by someone who is more experienced in the libraries.

osolmaz commented 1 year ago

Are you referring to this? https://github.com/pesho-ivanov/thesis-manim/blob/master/norm_play.py

It's already possible to do this by using tracker.duration. Can you elaborate how your solution works? What would happen if the scene had multiple animations for example. Would the durations of each be scaled linearly at the same rate until the total duration equals voiceover duration?

pesho-ivanov commented 1 year ago

Yes, norm_play.py does the linear stretching of the durations of all animations. In seed_heuristic.py you can see just the wrapping of voiceover tracker as the normed tracker I suggest.

Here is a minimal example showing how this normed tracker stretches all the animations in the with block to the duration of the text-to-speech.

with self.voiceover_norm(text="Each of them originates from a certain genome location.") as normed:
   normed.play(FadeIn(query.label))
   normed.play(Write(query))

Note that there is no need to specify any durations. It also works for more than 2 animations in the block by scaling them linearly.

osolmaz commented 1 year ago

Sounds good! I'll do a deep dive to your implementation soon and will try to incorporate it to the plugin.

It makes sense to allow enabling this behavior with a kwarg to to VoiceoverScene.voiceover(). IMO it is too opinionated to be the default behavior, but I can imagine how it could be very convenient in certain cases.