从音频中提取特征时如何修复(返回码:-9)

How to fix (returncode: -9) while extracting features from audio

我们已经对一个设备(由 raspberry pi 3 组成)进行了编程,让它坐在一个房间里,聆听,并根据现有的 GMM 描述房间的特征。我们的代码成功运行,直到它在第 17 次或第 19 次迭代时抛出错误。我们已将范围缩小到代码中出现问题的位置,但不确定原因。

我们是初级程序员,对于奇怪的格式表示歉意...这对我们来说都是全新的。

提前感谢您提供的任何帮助或见解!

from sklearn import preprocessing
import python_speech_features as mfcc

def calculate_delta(array):
    """Calculate and returns the delta of given feature vector matrix"""

    rows,cols = array.shape
    deltas = np.zeros((rows,20))
    N = 2
    for i in range(rows):
        index = []
        j = 1
        while j <= N:
            if i-j < 0:
                first = 0
            else:
                first = i-j
            if i+j > rows -1:
                second = rows -1
            else:
                second = i+j
            index.append((second,first))
            j+=1
        deltas[i] = ( array[index[0][0]]-array[index[0][1]] + (2 * (array[index[1][0]]-array[index[1][1]])) ) / 10
    return deltas

def extract_features(audio,rate):

        try:
            """extract 20 dim mfcc features from an audio, performs CMS and combines 
            delta to make it 40 dim feature vector"""    

            # audio is audio signal from which to compute features -> should be n*1 array
            # rate is samplerate of the signal we are working with
            # 0.025 is the length of the analysis window in seconds (default is 25ms)
            # 0.01 is the step between successive windows in seconds (default is 10ms)
            # 20 is number of cepstrum to return (default is 13)
            # append energy is true if zeroth cepstral coefficient is replaced with log of total frame energy
            # mfcc() returns a numpy array of size (NUMFRAMES by numcep) containing features, each row holds 1 feature vector 
            # further possible parameters & their defaults can be found at python-speech-features.readthedocs.io/en/latest/
            mfcc_feat = mfcc.mfcc(audio,rate, 0.025, 0.01, 20, appendEnergy = True)

            # Scale all data onto one scale, eliminating sparsity & following same concept of Normalization & Standardization 
            mfcc_feat = preprocessing.scale(mfcc_feat)

            delta = calculate_delta(mfcc_feat)

            combined = np.hstack((mfcc_feat,delta))
            print("Features extracted")
            return combined
        except Exception as e:
            print(e)
            print("Extract features failed.")

我们认为问题出在这一行:

 mfcc_feat = mfcc.mfcc(audio,rate, 0.025, 0.01, 20, appendEnergy = True

它给我们的错误是:

后端终止(返回代码:-9)

returncode: -9 可能意味着信号 9 这意味着

SIGKILL. The SIGKILL signal is sent to a process to cause it to terminate immediately (kill). In contrast to SIGTERM and SIGINT, this signal cannot be caught or ignored, and the receiving process cannot perform any clean-up upon receiving this signal.

这可能就是它没有被异常捕获的原因。