topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 1:15 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Adding silence to audio track?  (Read 13247 times)

Attronarch

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 147
    • View Profile
    • Donate to Member
Adding silence to audio track?
« on: January 09, 2016, 06:49 AM »
I have several hour-long audio tracks to which I have to add silence. It should go 30 seconds of music, 30 seconds of silence, and so on, until the end of track.

My first try was Audacity, which can add silence, but I couldn't figure it out how to add it to the whole track in same interval.

Any recommendations?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #1 on: January 09, 2016, 07:32 AM »
Someone who uses Audacity or another program may have specific instructions.  In the meantime I would suggest checking the Sourceforge forum for Audacity as someone may have asked the same question.  Also I found a write-up of 25 free audio editors.  One of them may have an automation feature as well as batch processing.

http://www.hongkiat....gital-audio-editors/

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #2 on: January 09, 2016, 11:40 AM »
I made a script, try it. It requires Autohotkey and ffmpeg (and ffprobe that is included with ffmpeg).
https://autohotkey.com/
http://ffmpeg.zeranoe.com/builds/

update: fixed bugs with ffmpeg path (previously only worked when ffmpeg was in same folder as script)

update2: get the newer version here https://www.donation...ex.php?topic=42184.0

Code: Autohotkey [Select]
  1. SetWorkingDir %A_ScriptDir%
  2.  
  3. ;30SecondSilencer
  4. ;adds 30 seconds silence every 30 seconds to an mp3 file
  5.  
  6. ;-------------------------
  7. ;CHANGE THESE PARAMETERS
  8. source = C:\folder\some music file.mp3
  9. workdir = C:\dir\
  10. chunksize = 30     ;length of each silence/music segment
  11. ffmpeg = C:\ffmpeg\ffmpeg.exe
  12. ;-------------------------
  13.  
  14. ;check paths
  15. SplitPath, source,,, ext, noext
  16. SplitPath, ffmpeg,,fdir
  17. if !FileExist(source) or !FileExist(workdir) or !FileExist(ffmpeg) or !FileExist(fdir "\ffprobe.exe")
  18.  
  19. ;Clear old files
  20. Filedelete %workdir%\30ss-silent.mp3
  21. Filedelete %workdir%\30ss_*.mp3
  22. Filedelete %workdir%\%noext%_30ss.mp3
  23. Filedelete %workdir%\30ss_*.txt
  24.  
  25. ;Get source duration in seconds
  26. ;http://superuser.com/a/945604
  27. RunWait %comspec% /c ""%fdir%\ffprobe.exe" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "%source%" >> "%workdir%\30ss_duration.txt""
  28. FileRead, dur, %workdir%\30ss_duration.txt
  29. length := Ceil(dur)
  30. if !length
  31.  
  32. ;split source into 30 second mp3 chunks
  33. ;http://stackoverflow.com/a/7945753
  34. steps := Ceil(length / chunksize) ; number of steps
  35. start = 0
  36. ToolTip, Split chunks...
  37. sleep 1000
  38. Loop, %steps%
  39. {
  40. c := StrLen(a_index)==1 ? "00" a_index : StrLen(a_index)==2 ? "0" a_index : a_index
  41. Run "%ffmpeg%" -ss %start% -i "%source%" -t %chunksize% "%workdir%\30ss_%c%.mp3" ,,Min
  42. start := start + chunksize
  43. ToolTip, %A_index% / %steps%
  44. }
  45.  
  46. ToolTip, Processing...  ;wait for ffmpeg to make all chunks
  47. {
  48.         pcount = 0
  49.         for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
  50.                 if InStr(process.Name,"ffmpeg.exe")
  51.                  pcount++
  52.         if pcount < 1
  53.          break
  54.         ToolTip Processing %pcount% left
  55.         sleep 400
  56. }
  57.  
  58. ;make 30 sec silent audio mp3 file
  59. ;http://stackoverflow.com/a/32027123
  60. ToolTip, make silent.mp3
  61. sleep 1000
  62. RunWait "%ffmpeg%" -f lavfi -i anullsrc -t 30 "%workdir%\30ss-silent.mp3",,Min
  63.  
  64.  
  65. ;Concatenate chunks and silence
  66. ;https://trac.ffmpeg.org/wiki/Concatenate
  67. ToolTip, Concatenate...
  68. Loop, Files, %workdir%\30ss_*.mp3
  69.  FileAppend, file '%workdir%\%A_LoopFileName%'`nfile '%workdir%\30ss-silent.mp3'`n, %workdir%\30ss_list.txt
  70. RunWait "%ffmpeg%" -nostats -loglevel 0 -f concat -i "%workdir%\30ss_list.txt" -c copy "%workdir%\%noext%_30ss.mp3" ,,Min
  71.  
  72. ;clear chunks
  73. Filedelete %workdir%\30ss_*.mp3
  74.  
  75. ToolTip, Finished!
  76. sleep 1000

Out of curiousity what will you use the audio files for? crossfit/interval training perhaps?
« Last Edit: January 10, 2016, 03:57 AM by Nod5 »

Attronarch

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 147
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #3 on: January 09, 2016, 12:04 PM »
Wow, thank you very much!

I've changed lines 10,11 and 13, but run into some trouble:

[REMOVED]

It is for my mother, she is Physical Education teacher, and among other things holds aerobic classes.
« Last Edit: January 10, 2016, 12:52 AM by Attronarch »

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #4 on: January 09, 2016, 12:38 PM »
shouldn't the cuts fade in/out, instead of abrupt cutting?  :-\

Attronarch

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 147
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #5 on: January 09, 2016, 02:02 PM »
shouldn't the cuts fade in/out, instead of abrupt cutting?  :-\

No, she didn't have such requirement.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #6 on: January 09, 2016, 02:07 PM »
I see the problem, my bad. I fixed it in the post above. It should work now.

Attronarch

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 147
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #7 on: January 09, 2016, 02:22 PM »
I see the problem, my bad. I fixed it in the post above. It should work now.

No errors pop out, but I also cannot find final mp3. I see work folder being filled with chunks, but after it is finished everything is deleted except:

  • 30ss-silent.mp3
  • 30ss_duration.txt

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #8 on: January 09, 2016, 02:27 PM »
shouldn't the cuts fade in/out, instead of abrupt cutting?  :-\
Should be doable with this https://ffmpeg.org/f...filters.html#afade-1 , if anyone gets the hang of the correct commands line for fade in / out then post a snippet here and I'll integrate it in the script.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #9 on: January 09, 2016, 02:29 PM »
No errors pop out, but I also cannot find final mp3. I see work folder being filled with chunks, but after it is finished everything is deleted except:

  • 30ss-silent.mp3
  • 30ss_duration.txt
There should be a new file named <workdir>\<source file name>_30ss.mp3

edit: I've tested it multiple times again and it works here.

the script also should create the file 30ss_list.txt , is that file present after you run the script? If so open it and check that the contents look like this
file '<workdir path>\30ss_001.mp3'
file '<workdir path>\30ss-silent.mp3'
file '<workdir path>\30ss_002.mp3'
file '<workdir path>\30ss-silent.mp3'
...
« Last Edit: January 09, 2016, 02:45 PM by Nod5 »

Attronarch

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 147
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #10 on: January 10, 2016, 12:53 AM »
Works perfect, thank you.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Adding silence to audio track?
« Reply #11 on: January 10, 2016, 03:56 AM »
newer version of 30SecondSilencer posted in the Coding Snacks section
https://www.donation...ex.php?topic=42184.0