Is [Export deck to audio] still usable?

addon code: 2095022381
This seems to be a very useful addon. High chance it is still usable in older version of Anki, since there are some review from earlier this year.
I tried to run the addon on both windows and ubuntu in older anki version. But doesnt work for both since the addon produced an audio file of 8kb and last for 8 secs of silence.
I have a guess that the problem probably caused by my version of ffmpeg, which seems to require a lot of works to fix. So I just want to ask if anyone here is still using this addon and what is your settings of Anki & ffmpeg for it.

Hello. I used the “Export deck to audio (Anki 2.1)” add-on successfully a few years ago, but as you note, it appears to have been broken for a while. “Supported Anki versions: 2.1.0-2.1.21+ (Updated 2022-05-17)”

I don’t have the programming skills to fix the program, but I’ve got a couple of suggestions.

Two alternatives I’ve tested both work with
Windows 10
Version 23.12.1
Python 3.9.15 Qt 6.6.1 PyQt 6.6.1

  1. If you just want to play your selected audio randomly in Anki and specify the number of seconds delay without exporting the combined audio, use “Preview Slideshow (Fixed for Anki 23 by Shige)” add-on code 1621302762.

  2. To export the audio, use “Media Exporter add-on code 567329012” and the batch file below.

Select the cards you want to get the audio for (see Media Exporter add-on for details). You can select by note, tag, flag, deck, etc. Export the media to a folder of your choice.

I had Microsoft Copilot write a simple batch command to export the audio to a folder. The batch file will sort your exported audio files randomly, allow you to specify the number of seconds between audio and then export the audio to a single file.

You’ll need PowerShell version greater than 6.0 and ffmpeg in your path setting.

It could surely be written more elegantly in Python, but I’m not a programmer and I assume not every Anki user has Python. I wanted this batch file to be as simple as possible. If anyone wants to rewrite in a better manner, please share with us. Thanks.

Batch file is below:

type or paste code here


@echo off
setlocal enabledelayedexpansion
chcp 65001>NUL

REM Edit this batch file to change the "audio_folder=C:\path\to\youraudiofolder" to the folder where audio files are stored.
REM Batch file works with mp3 files, but you can edit that to any other audio file format.
REM The batch file needs PowerShell version greater than 6.0 and ffmpeg in your path settings.
REM If you see the message "pwsh is not recognized as an internal or external command, operable command or batch file, then you probable don't have PowerShell greater that 6.0 installed.
REM The batch file will randomly sort, input your desired number of seconds of silence and then combine the audio files in your audio folder to a single audio file
REM The audio file and a shuffle text list are output to a subfolder called "CombinedAudio".

echo If you see the message "pwsh is not recognized as an internal or external command, operable command or batch file", then you probably don't have PowerShell greater that 6.0 installed.

:: Set the path to the folder containing the audio files
set "audio_folder=C:\path\to\youraudiofolder"

:: Check if ffmpeg is in the environment variables path
echo Checking for ffmpeg...
where /q ffmpeg
if %errorlevel% neq 0 (
    echo ffmpeg not found in environment variables path
    exit /b
)
echo Success. ffmpeg found.

:: Check if there is a folder called "Combined Audio" under "%audio_folder%"
if not exist "%audio_folder%\Combined Audio" (
    mkdir "%audio_folder%\Combined Audio"
)

:: Check if there is a folder called "TempAddSilenceAudio" under "%audio_folder%\Combined Audio"
if not exist "%audio_folder%\Combined Audio\TempAddSilenceAudio" (
    mkdir "%audio_folder%\Combined Audio\TempAddSilenceAudio"
)

:: Ask the user for the number of seconds of silence between each audio file
set /p seconds=Input how many seconds of silence between each audio file: 

:: Add silence to the end of each audio file and save them in the TempAddSilenceAudio folder
for /f "delims=" %%i in ('dir "%audio_folder%\*.mp3" /b') do (
    set "input_file=%audio_folder%\%%i"
    for %%f in ("!input_file!") do set "filename=%%~nf"
    set "output_file=%audio_folder%\Combined Audio\TempAddSilenceAudio\!filename!_silence.mp3"
    ffmpeg -i "!input_file!" -af apad=pad_dur=!seconds! "!output_file!" > NUL 2>&1
)

:: Create a list of all audio files in the TempAddSilenceAudio folder
(for /f "delims=" %%i in ('dir "%audio_folder%\Combined Audio\TempAddSilenceAudio\*.mp3" /b /s') do (
    echo file '%%i'
)) > "%audio_folder%\Combined Audio\TempAddSilenceAudio\temp_file_list.txt"

:: Get the current date and time, and format them for use in a filename
set "filename_date=%date:/=-%"
set "filename_time=%time::=-%"
set "filename_time=!filename_time: =0!"

:: Randomly sort the lines in temp_file_list.txt using PowerShell and save to shuffle_list.txt with date and time in the Combined Audio folder
pwsh -Command "Get-Content '%audio_folder%\Combined Audio\TempAddSilenceAudio\temp_file_list.txt' | Sort-Object {Get-Random} | Out-File -FilePath '%audio_folder%\Combined Audio\shuffle_list_!filename_date!_!filename_time!.txt' -Encoding utf8"

:: Delete the temporary file list
del "%audio_folder%\Combined Audio\TempAddSilenceAudio\temp_file_list.txt"

:: Use ffmpeg to combine all the audio files in "%audio_folder%\Combined Audio\TempAddSilenceAudio" folder
echo Audio files are being randomly sorted and combined to "%audio_folder%\Combined Audio". Please wait for finish...
ffmpeg -f concat -safe 0 -i "%audio_folder%\Combined Audio\shuffle_list_!filename_date!_!filename_time!.txt" -c copy "%audio_folder%\Combined Audio\Combined_Audio_!seconds!_Seconds_Silence_!filename_date!_!filename_time!.mp3" > NUL 2>&1

echo Audio files have been combined and shuffled successfully.

:: Delete the TempAddSilenceAudio folder and all its contents
rd /s /q "%audio_folder%\Combined Audio\TempAddSilenceAudio"

pause