(.)(.) dev thoughts ...

sampling audio files with python
2017-09-27 22:09:00

To be quick - for recent idea I need to segment audio file, perfectly after one speaker finish his sentence and second speaker start talking. Also I need to detect number of unique speakers in audio.

There are plenty of libraries out there from lot's of Universities or proffessor or Phd's. All of them are commonly using same ideas from speech recognition topic. I won't be digging to them in this post. Unfortunately none of them is working perfectly for this task.

So I got my hands dirty in audio by using python and I found out I need some utility to help me with cutting / plotting audio files so I can progress faster.
I created some utility class for doing it using scipy matplotlib and numpy. There is not much code now but you can use it freely if you want to:

  • open file and convert it to mono
  • cut seconds from audio file
  • get seconds of audio file
  • process audio file using custom method
  • save file wrapper over scipy.io.wav
  • spectrogram with matplotlib.specgram

You can try it just by typing:

python audio.py test.wav

But as I wrote before you need scipy, matplotlib and numpy to use it.

If and when you manage to execute it against your wav file without errors you should see spectrogram chart with wav file plot. On X axis it would be number of seconds. On Y probably signal amplitude but I could be wrong.
Plot of spectrogram

If you look to the end of the code it is simply one liner.


I will try to update library and also this post with list of features as I need some more methods.
Also maybe I will write something more about my audio segmentation and speaker diarisation struggles.

I embedded github gist below so it will be easier to copy it.