I am currently working on a django project, in which i need to record the users audio and sent it to the server for processing. i have successfully recorded the audio using webRTC and passed it to views using an ajax request. But when i try to load the audio file using librosa for prosessing it gives an error for unknown file format.
to check what if i wrong with the file formats while recording tried different file formats which are supported by librosa and webRTC both
- audio/wav;codec=MS_PCM
- audio/wav;codec=MS_GSM610
to check if i had a problem with the file in receiving it on server i did upload the file on the server and i found that the file gets uploaded on the server and can be played on player directly.
code that i used to upload the file and retrive it (note: i directly gave the path to the file to any recorded file just to check)
def voice2(request):
if request.method=='GET':
return render(request,'record3.html')
else:
if request.method == 'POST' :
print(request.FILES)
audio=request.FILES.get("audioData")
print(audio)
file = request.FILES['audioData']
path = default_storage.save('media/somename.wav', ContentFile(file.read()))
(os.path.join(settings.MEDIA_ROOT, path))
sig, samplerate = librosa.load(r'C:\Users\KRISHNA DAVE\project\tempproject\media\media\somename.wav')
return render(request, 'record3.html')
now to check librosa couldn't read the file or the file had problem, this time i downloaded a sample audio file from the internet, then i created a new audio.py file in which i made a attempt to load both the files(the one i uploaded and the one i downloaded)
import librosa
#downloaded from internet
a,b=librosa.load(r"C:\Users\KRISHNA DAVE\Music\samplewav.wav")
print(a,b)
#recorded file
y, sr = librosa.load(r"C:\Users\KRISHNA DAVE\project\tempproject\media\media\somename.wav")
print(y,sr)
here i found that the downloaded file was loaded successfully but the file i recorded was still not loaded(i still get the error that the file is in unknown format)
I am still unable to understand how should i solve this problem. Should i replace using webRTC with something else or should i change the audio codec or there is a need to use different libraries(note: i already used librosa which also indirectly use soundfile and also tried soundfile directly, and i cannot use pyAudioAnalysis because i am using python 3.6 and pyAudioAnalysis is incompatible with this version)?