0

I have some long audio files.I want to split this audio file into multiple short length audio file using python.Ex:The audio long length is more than 1 hour and want to split into multiple short length 5s files. i want to extract features for the whole audio file in each 5s.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
eku
  • 11
  • 1
  • 2
  • 6

1 Answers1

0

There are two issues in your question.

  1. Splitting the audio
  2. Extracting features.

and both of them have the same, underlying, key information: sampling frequency.

The duration of an audio signal, in seconds, and the sampling frequency used for the audio file, define the amount of samples that an audio file has. An audio sample is (in simplified terms) one value of the audio signal in your hard-disk or computer memory.

The amount of audio samples, for a typical wav file, are calculated based on the formula sr * dur, here sr is the sampling frequency in Hz (e.g. 44100 for a CD quality signal) and dur is the duration of the audio file in seconds. For example, a CD audio file of 2 seconds has 44100 * 2 = 88200 samples.

So:

To split an audio file in Python, you first have to read it in a variable. There are plenty libraries and functions out there, for example (in a random order):

  • scipy.io.wavfile.read
  • wave module

and others. You can check this SO post for more info on reading a wav file.

Then, you just have to get N samples, e.g. my_audio_1 = whole_audio_file[0:5*sr].

BUT!!!

If you just want to extract features for every X seconds, then it is no need to split the audio manually. Most audio feature extraction libraries, do that for you.

For example, in librosa you can control the amount of the FFT points, which roughly are equivalent to the length of the audio that you want to extract features from. You can check, for example, here: https://librosa.org/doc/latest/feature.html

Xxxo
  • 1,784
  • 1
  • 15
  • 24