Try to search your question here, if you can't find : Ask Any Question Now ?

Unable to use Multithread for librosa melspectrogram

HomeCategory: stackoverflowUnable to use Multithread for librosa melspectrogram
Avatarcraig asked 5 months ago

I have over 1000 audio files (it’s just a initial development, in the future, there will be even more audio files), and would like to convert them to melspectrogram.

Since my workstation has a Intel® Xeon® Processor E5-2698 v3, which has 32 threads, I would like to use multithread to do my job.

My code

import os
import librosa
from librosa.display import specshow
from natsort import natsorted
import numpy as np
import sys 
# Libraries for multi thread
from multiprocessing.dummy import Pool as ThreadPool
import subprocess
pool = ThreadPool(20) 

songlist = os.listdir('../opensmile/devset_2015/')
songlist= natsorted(songlist)

def get_spectrogram(song):
    y, sr = librosa.load('../opensmile/devset_2015/' + song)

    ## Add some function to cut y
    y_list = y

    for i, y_i in enumerate([y_list]): # can remove for loop if no audio is cut
        S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128,fmax=8000)
  './Test/' + song + '/' + str(i), S)
            os.makedirs('./Test/' + song)
  './Test/' + song + '/' + str(i), S)
        print("done saving"), songlist)

My Problem

However, my script freezes after finished the first conversion.

To debug what’s going on, I commented out S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128,fmax=8000) and replace it by S=0.
Then the multi-thread code works fine.

What’s wrong with the librosa.feature.melspectrogram function? Does it not support multi-thread? Or is it a problem of ffmpeg? (When using librosa, it asks me to install ffmpeg before.)

1 Answers
Best Answer
AvatarJyoti answered 5 months ago
Your Answer

6 + 19 =

Popular Tags

WP Facebook Auto Publish Powered By :