Trimming audio in python

OK, so I used pyaudio too, but from the fact that I was looking at the wave module, I could probably help me here.

So, I'm trying to add a trim function to my program, I mean, I'm trying to allow the user to find wav parts. that he / she does not like and has the ability to cut the wave file if he wants it.

so far I have used pyaudio for simple playback, and pyaudio is very simple when it comes to recording from an input device.

I searched on pyaudio for everything I could to trim the audio, but I really found something that could help me. Although on the built-in wave module, I see that there are ways to set the position.

Do I have to have a loop or instruction so that the program knows which positions to record, and then either pyaudio or the wave module for recording a song from user positions (start, end)? Will my program work efficiently if I approach it like this?

+4
source share
1 answer

Suppose you read in a wave file using scipy.

Then you need to have “edit points”. These are the values ​​and values ​​(in seconds, for example) that the user would like to save. you can get them from a file or display a wave file and get mouse clicks. If the user provides parts of the audio file that are to be deleted, this must first be canceled.

, .

import scipy.io.wavfile
fs1, y1 = scipy.io.wavfile.read(filename)
l1 = numpy.array([  [7.2,19.8], [35.3,67.23], [103,110 ] ])
l1 = ceil(l1*fs1)#get integer indices into the wav file - careful of end of array reading with a check for greater than y1.shape
newWavFileAsList = []
for elem in l1:
  startRead = elem[0]
  endRead = elem[1]
  if startRead >= y1.shape[0]:
    startRead = y1.shape[0]-1
  if endRead >= y1.shape[0]:
    endRead = y1.shape[0]-1
  newWavFileAsList.extend(y1[startRead:endRead])


newWavFile = numpy.array(newWavFileAsList)

scipy.io.wavfile.write(outputName, fs1, newWavFile)
+1

All Articles