Advertisement
zefie

split audio by time

Nov 24th, 2022 (edited)
2,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3.  
  4. rem Update these paths as needed
  5. set FFMPEG=C:\bin\foobar2000\encoders\x64\ffmpeg.exe
  6. set SOX=C:\bin\foobar2000\encoders\sox\sox.exe
  7.  
  8. rem Usage: slice.bat pathtofile.ext sec
  9. rem Example: slice.bat music.wav 16
  10.  
  11. rem clean old data
  12. del *.wav
  13. del *.flac
  14.  
  15. if %2==element (
  16.     set splittime=13.71
  17. ) else (
  18.     if %2==lunar160 (
  19.         set splittime=6
  20.     ) else (
  21.         set splittime=%2
  22.     )
  23. )
  24.  
  25. echo Easy Cheesy Loopy Peasy
  26. echo Splitting %1 into slices (Segment Time: !splittime!) ...
  27.  
  28. rem Convert to WAV
  29. if %~x1==".mp3" (
  30.     set FILTER=-af "silenceremove=start_periods=1:start_duration=1:start_threshold=-60dB:detection=peak,aformat=dblp,areverse,silenceremove=start_periods=1:start_duration=1:start_threshold=-60dB:detection=peak,aformat=dblp,areverse"
  31. )
  32. %FFMPEG% -loglevel quiet -i %1 -c:a pcm_s24le -ac 2 -ar 48000 %FILTER% temp.wav
  33.  
  34. rem Use sox for accurate time splitting
  35. %SOX% temp.wav slice.wav trim 0 !splittime! : newfile : restart
  36. del temp.wav
  37.  
  38. rem Encode FLAC
  39. for /f "delims=" %%D in ('dir /b *.wav') do (
  40.     echo Converting %%D to flac ...
  41.     C:\bin\foobar2000\encoders\x64\flac -8 --totally-silent %%D
  42.     del %%D
  43. )
  44.  
  45. goto :EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement