Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): ability to add sounds #489

Conversation

PeculiarProgrammer
Copy link
Contributor

@PeculiarProgrammer PeculiarProgrammer commented Nov 10, 2024

You can now add sounds to your presentation!

This PR modifies the code to automatically add the sounds to the slides. This works with either manim-voiceover or self.add_sound.

Here are the currently supported presentation mediums:

  • Qt (fully)
  • Powerpoint (fully)
  • Reveal (somewhat, the first slide can't show audio)
  • PDF (obviously no)

Fixes Issue

Closes #258
Closes #375

Check List

Check all the applicable boxes:

  • I understand that my contributions needs to pass the checks;
  • If I created new functions / methods, I documented them and add type hints;
  • If I modified already existing code, I updated the documentation accordingly;
  • The title of my pull request is a short description of the requested changes.

Note For Reviewers

I modified the BasicExample scene to use manim-voiceover in the example file, but neglected to include manim-voiceover as a dependency. I originally had it as an extra, but I'm not sure what you want so I'll leave it not included as a dependency for now. Modifying the example video might also be beneficial along side this change.

Edit: manim-voiceover is now included as the voiceover extra. The example code has been modified to not have a voiceover when manim-voiceover is not installed, and to use either GTTS or OpenAI when it is installed.

PeculiarProgrammer and others added 7 commits November 10, 2024 15:31
The audio files from manim-voiceover now get added into the manim-slides configuration.

Next step: integrate into Qt and Reveal. Maybe Powerpoint.
Audio is now merged into the slides. All that should be done now is to let Qt, Powerpoint and Reveal take the audio.
Copy link

codecov bot commented Nov 10, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 28 lines in your changes missing coverage. Please review.

Project coverage is 80.14%. Comparing base (3dbe12b) to head (c25bd5b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
manim_slides/utils.py 8.69% 21 Missing ⚠️
manim_slides/slide/base.py 33.33% 4 Missing ⚠️
manim_slides/slide/manim.py 85.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #489      +/-   ##
==========================================
- Coverage   81.05%   80.14%   -0.91%     
==========================================
  Files          23       23              
  Lines        1884     1939      +55     
==========================================
+ Hits         1527     1554      +27     
- Misses        357      385      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

PeculiarProgrammer and others added 6 commits November 11, 2024 10:28
pre-commit.ci informed me that line 51 of manim_slides/convert.py shouldn't have the no-type checker on my computer, but it is required on the workflow.
@PeculiarProgrammer
Copy link
Contributor Author

PeculiarProgrammer commented Nov 11, 2024

I added manim-voiceover as an extra (it is currently included in full, maybe it should not be). With that, the BasicExample scene now has a voiceover. It might be better to add an additional scene instead to demonstrate the voiceover.

A slight issue I encountered with manim-voiceover, though, is that it attempts to install an outdated version of openai-whisper. This is easily avoided by adding the newer version in override-dependencies, but for some reason, this seems to be ignored in Python 3.12 on Ubuntu. This messes up one of the workflows and I'm not sure how I can fix this.

Update: Only on Python 3.12 Ubuntu is no valid version of Trenton found. The uv override-dependencies only affects uv and not pip, so for the time being it seems like it won't be possible to fix unless if manim-voiceover changes its dependency or the user installs the correct version manually later on. Also, they could always just not use the manim-voiceover extra.

@jeertmans jeertmans changed the title Ability to add sounds feat(lib): ability to add sounds Nov 12, 2024
@jeertmans
Copy link
Owner

Hi @PeculiarProgrammer, thank you for your contribution!

However, it is unlikely that I will accept such a feature, for two reasons:

  • This duplicates part of the code that is already present inside Manim, because Manim already supports audio;
  • This adds a dependency that is not really required: manim-voiceover should be one of the many ways to add audio, and hence be added only if people want to. Especially here because OpenAI requires an API key...

Actually, audio is already supported by manim-slides present and manim-slides convert --to=html players. The issue is that Manim adds audio after partial movie files are concatenated. I think a better solution would be to work on ManimCommunity/manim#3763, which I started some time ago but didn't have much time to work on this, and hopefully fix the few issues I had with encodings. This PR adds the audio to partial movie files instead, which means audio will not be present in each slide.

Your PR is a good solution, but not the ideal one according to me.

Regarding the voice-over example, I think it would be great to include such an example in the online documentation, but that still needs ManimCommunity/manim#3763 to be merged (and released) first.

What do you think?

@jeertmans jeertmans added enhancement New feature or request lib Related to the library (a.k.a. module) labels Nov 12, 2024
@jeertmans
Copy link
Owner

jeertmans commented Nov 12, 2024

  • Reveal (somewhat, the first slide can't show audio)

For your information, this is a browser limitation. If an HTML page contains an autoplay video that isn't tagged muted, most browsers will block the video to avoid spammy videos when you arrive at a webpage. This is why I automatically mute the first slide. A solution is simply to have a dummy blank slide at the beginning.

@PeculiarProgrammer
Copy link
Contributor Author

When I was writing this code, I did realize that it was a bit "hacky." Admittedly, adding manim-voiceover as an extra does seem unnecessary. For reference, I only did it because you suggested it in #258.

It would definitely be better to have manim merge ManimCommunity/manim#3763 instead of this one. So I'll close this.

Out of interest, did you manage to get ManimCommunity/manim#3763 working with just the tests omitted, or have you not yet finished it?

@jeertmans
Copy link
Owner

No I couldn't make it work, for two reasons:

  • no all video encodings work the same and some (especially transparent I think) encodings did not work
  • I had issues when trying to add audio because the audio rate is not the video rate, and adding them by segments can mean you need to break the audio at a non-integer number of audio frames, which means some frames are lost (or you create more frames).

If you have some time, you can try to contribute to my PR directly. I will see how I can give you write accesses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lib Related to the library (a.k.a. module)
Projects
None yet
2 participants