DillonWall / generate-batch-audio-anki-addon

An addon that downloads and attaches audio to flashcards in bulk from URLs. Made for Anki, an SRS flashcard application
https://ankiweb.net/shared/info/1156270186
Apache License 2.0
14 stars 6 forks source link

Normalize Audio #18

Open ccos89 opened 7 months ago

ccos89 commented 7 months ago

First off - thank you for this addon, it's a total lifesaver for mining from my ereader. My only improvement would be this- in the future would there be any way to normalize the volume of the audio being added to the cards? This could be accomplished through ffmpeg with the loudnorm filter processing the audio before it gets added to the media folder, and could be an optional checkbox. But the audio levels get pretty wacky from Forvo a lot of the time so would be nice to not have people yell in my ear. Currently to remedy this AFAIK one would have to run ffmpeg on the files in the media folder and then reupload media during sync, which is not a short process when you have about ~25k cards...

DillonWall commented 6 months ago

Thank you for the feature suggestion. It may take me some time to get around to adding new features, but I will put my thoughts here in case someone else would like to work on it.

It looks like the Python pydub package would work well for this task, but there is a catch. According to the documentation, You can open and save WAV files with pure python. For opening and saving non-wav files – like mp3 – you'll need ffmpeg or libav.

This means that we will need some sort of error handling that checks if the files can be opened with pydub. Otherwise we should warn the user (probably when they check the box to normalize audio) that Only .wav files will be normalized, please install ffmpeg or libav.

I think the best way to implement this would be to add a checkbox for normalizing audio, and either a slider or number box for the desired average dBFS.

An optional feature we could easily add alongside this change would be a combo box for desired audio format. I know many people wish to convert audio files to formats with small sizes, and this way, people would not need to use another addon to convert these files afterwards. Again, this would require a warning when the user attempts to use a non-wav format, but does not have ffmpeg or libav installed.