0

I made a Voice classifier in python which classifies My voice and My friend's voice based on uploaded sound file, locally works fine but the doesn't run on deployment on checking the Heroku logs I got this error

raise OSError('sndfile library not found')
OSError: sndfile library not found

sndfile comes along with SoundFile and SoundFile does install perfectly in my machine and runs perfectly works locally but on deployment, I get those errors

how do I solve this error and get my Heroku app running ??

these are codes ...

from flask import Flask, render_template, request 
import librosa
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import numpy as np
import pandas as pd
import os

app = Flask(__name__)
app.debug = True
path = (os.path.abspath(os.path.dirname(__file__).replace("",""))+"/asset/feature.csv")
#print(path)
dt = pd.read_csv(path)
#print(dt.head())


@app.route('/')
def home():

    return render_template('page.html')

@app.route('/upload', methods=['POST'])
def upload():
    file = request.files['audio']
    audio = file 
    y , sr = librosa.load(audio, mono=True, duration=1)
    #print(audio)

    #features
    chroma_stft = librosa.feature.chroma_stft(y=y, sr=sr)
    spec_cent = librosa.feature.spectral_centroid(y=y, sr=sr)
    spec_bw = librosa.feature.spectral_bandwidth(y=y, sr=sr)
    rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)
    zcr = librosa.feature.zero_crossing_rate(y)
    mfcc = librosa.feature.mfcc(y=y, sr=sr)

    #loading up variables 
    chroma_stft = np.mean(chroma_stft)
    spec_cent = np.mean(spec_cent)
    spec_bw = np.mean(spec_bw)
    rolloff = np.mean(rolloff)
    zcr = np.mean(zcr)
    mfcc = np.mean(mfcc)

    train, test = train_test_split(dt)

    #print(train.shape)
    #print(test.shape)

    train_X = train[['chroma_stft','spec_cent','spec_bw','rolloff','zcr','mfcc']]
    train_y = train.prognosis

    test_X = test[['chroma_stft','spec_cent','spec_bw','rolloff','zcr','mfcc']]
    test_y = test.prognosis

    #knn
    model = KNeighborsClassifier(n_neighbors=3)
    model.fit(train_X, train_y)

    val = np.array([chroma_stft,spec_cent,spec_bw,rolloff,zcr,mfcc])
    val=val.reshape(1,-1)
    prediction = model.predict(val)

    if mfcc == 0 :
        data = False
    else :
        data = True
    return render_template('page.html',data=data, predicted=prediction, init=True, audio_dt=file)  

if __name__ == "__main__":
    app.run()

requirements.txt

audioread==2.1.8
cffi==1.14.0
click==7.1.2
decorator==4.4.2
Flask==1.1.2
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
joblib==0.14.1
librosa==0.7.2
llvmlite==0.32.0
MarkupSafe==1.1.1
numba==0.49.0
numpy==1.18.3
pandas==1.0.3
pycparser==2.20
python-dateutil==2.8.1
pytz==2020.1
resampy==0.2.2
scikit-learn==0.22.2.post1
scipy==1.4.1
six==1.14.0
SoundFile==0.10.2
Werkzeug==1.0.1

Procfile

web: gunicorn app:app --preload

It would be very Nice if someone Soves this issue thanks in advance

davidism
  • 121,510
  • 29
  • 395
  • 339
vIvId_gOat
  • 358
  • 2
  • 13

0 Answers0