use pre-built model to predict audio file

i am using this code to build a model that recognizes emotions in speech, but i can't figure out how to use it after loading it in a new python file. this is what i have but the results are always the same no matter what sound file i use.

model_audio =  tf.keras.models.load_model(audio_emotion_classifier_tess.h5)
path = YAF_back_angry.wav


def extract_features(path):
    data, sample_rate = librosa.load(path, duration=2, offset=0.6, sr=8025)
    # ZCR
    result = np.array([])
    zcr = np.mean(librosa.feature.zero_crossing_rate(y=data).T, axis=0)
    result=np.hstack((result, zcr)) # stacking horizontally

    # Chroma_stft
    stft = np.abs(librosa.stft(data))
    chroma_stft = np.mean(librosa.feature.chroma_stft(S=stft, sr=sample_rate).T, axis=0)
    result = np.hstack((result, chroma_stft)) # stacking horizontally

    # MFCC
    mfcc = np.mean(librosa.feature.mfcc(y=data, sr=sample_rate).T, axis=0)
    result = np.hstack((result, mfcc)) # stacking horizontally

    # Root Mean Square Value
    rms = np.mean(librosa.feature.rms(y=data).T, axis=0)
    result = np.hstack((result, rms)) # stacking horizontally

    # MelSpectogram
    mel = np.mean(librosa.feature.melspectrogram(y=data, sr=sample_rate).T, axis=0)
    result = np.hstack((result, mel)) # stacking horizontally
    
    return result


X = extract_features(path)
X = X.reshape(1, -1)
x_test = scaler.fit_transform(X)
predict_audio=model_audio.predict(x_test)
print(predict_audio)

Topic tensorflow deep-learning scikit-learn python

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.