0

I am new to Python, please bear with me. I have been able to get so far with the help of Google/StackOverflow and youtube :). So I have a long (2 hours) *.wav file. I want to mute certain parts of that file. I have all of those [start], [stop] timestamps in the "Timestamps.txt" file in seconds. Like this:

   0001.000 0003.000
   0744.096 0747.096
   0749.003 0750.653
   0750.934 0753.170
   0753.210 0754.990
   0756.075 0759.075
   0760.096 0763.096
   0810.016 0811.016
   0815.849 0816.849

What I have been able to do is read the file and isolate each tuple. I have just output the first tuple and printed it to check if everything looks good. It seems that the isolation of tuple works :) I plan to count the number of tuples (which is 674 in this case) and put in a 'for loop' according to that count and change the start and stop time according to the tuple. Perform the loop on that single *.wav file and output on file with muted sections as the timestamps. I have no idea how to implement my thinking with FFMPEG or any other utility in Python e.g pydub. Please help me.

   with open('Timestamps.txt') as f:
   data = [line.split() for line in f.readlines()]
   out = [(float(k), float(v)) for k, v in data]

   r = out[0] 
   x= r[0]
   y= r[1]
   #specific x and y values
   print(x)
   print(y)
Adil Azeem
  • 11
  • 3
  • import ffmpy import os os.system("ffmpeg -i 27.wav -af volume=enable='between(t,x,y)':volume=0 output.wav") This gives a empty output file – Adil Azeem Apr 20 '20 at 09:36

1 Answers1

0

I have made this solution but this will take ages to run :)

with open('Timestamps.txt') as f:
   data = [line.split() for line in f.readlines()]
   out = [(float(k), float(v)) for k, v in data]

   count = len(out)

   import ffmpy
   import os

   for o in range(count):

       r= out[o]
       x= r[0]
       y= r[1]

       os.system("ffmpeg -y -i %d.wav -af volume=enable='between(t,%d,%d)':volume=0 %d.wav" %(o,x,y,o+1))
       r= 0
       x= 0
       y= 0
       file= "%d.wav" %o
       os.remove(file)
Adil Azeem
  • 11
  • 3