问题
I have deployed librosa, matplotlib and all its required dependencies using AWS-Lambda-layers and it's working fine. When I send a .wav
file from postman using the binary format the librosa.load() gives me the following error
{
"errorMessage": "module 'soundfile' has no attribute 'SoundFile'",
"errorType": "AttributeError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 83, in lambda_handler\n clip, sample_rate = librosa.load(file_name)\n",
" File \"/opt/python/librosa/core/audio.py\", line 146, in load\n with sf.SoundFile(path) as sf_desc:\n"
]
}
My lambda_function is as follows
import json
import base64
import boto3
import scipy.io.wavfile as wav
import scipy.signal as signal
import numpy as np
from matplotlib import pyplot as plt
import os
os.environ ["NUMBA_CACHE_DIR"] = "/tmp"
import librosa
import librosa.display
from scipy import signal
import wavio
import wave
import matplotlib.pylab as plt
from scipy.signal import butter, lfilter
global filename
global file_name
def lambda_handler(event, context):
s3 = boto3.client("s3")
# retrieving data from event. Which is the wave audio file
get_file_content_from_postman = event["content"]
# decoding data. Here the wava file is converted back to binary form
file_name = base64.b64decode(get_file_content_from_postman)
plt.interactive(False)
clip, sample_rate = librosa.load(file_name)
clip= librosa.resample(clip, sample_rate, 2000)
Any idea what is the issue and how to resolve it?
来源:https://stackoverflow.com/questions/64657260/librosa-load-gives-error-module-soundfile-has-no-attribute-soundfile