Commit 88281141 authored by Malsha Rathnasiri's avatar Malsha Rathnasiri

fix issues

parent 7108789d
venv/ venv/
backend/output.wav
backend/backend/output.m4a
ffmpeg-2022-08-03-git-d3f48e68b3-essentials_build/ffmpeg.exe
ngrok.exe
ffmpeg-2022-08-03-git-d3f48e68b3-essentials_build/ffplay.exe
ffmpeg-2022-08-03-git-d3f48e68b3-essentials_build/ffprobe.exe
...@@ -49,7 +49,7 @@ export const AudioRecorder = ({ setDetectedText }) => { ...@@ -49,7 +49,7 @@ export const AudioRecorder = ({ setDetectedText }) => {
} }
playSound(uri) playSound(uri)
FileSystem.uploadAsync("https://1ec4-112-134-210-155.ap.ngrok.io/mlmodels/detect/", uri, { headers: headers, uploadType: FileSystem.FileSystemUploadType.MULTIPART }) FileSystem.uploadAsync("https://ebf4-2401-dd00-10-20-4ca2-920b-4150-8178.in.ngrok.io/mlmodels/detect/", uri, { headers: headers, uploadType: FileSystem.FileSystemUploadType.MULTIPART })
.then(data => JSON.parse(data.body)) .then(data => JSON.parse(data.body))
.then(data => { console.log({ result: data }); setDetectedText(data.result); setTimeout(() => setDetectedText(''), 1000) }) .then(data => { console.log({ result: data }); setDetectedText(data.result); setTimeout(() => setDetectedText(''), 1000) })
.catch(err => console.log({ err })) .catch(err => console.log({ err }))
......
...@@ -20,17 +20,17 @@ def predict(samples): ...@@ -20,17 +20,17 @@ def predict(samples):
all_label = pickle.load(f1) all_label = pickle.load(f1)
print('loaded labels') print('loaded labels')
f2 = open('all_waves_file.txt', 'rb') # f2 = open('all_waves_file.txt', 'rb')
all_wave = pickle.load(f2) # all_wave = pickle.load(f2)
print('loaded waves') # print('loaded waves')
le = LabelEncoder() le = LabelEncoder()
y = le.fit_transform(all_label) y = le.fit_transform(all_label)
classes = list(le.classes_) classes = list(le.classes_)
train_data_file = open("train_data_file.txt", 'rb') # train_data_file = open("train_data_file.txt", 'rb')
[x_tr, x_val, y_tr, y_val] = np.load(train_data_file, allow_pickle=True) # [x_tr, x_val, y_tr, y_val] = np.load(train_data_file, allow_pickle=True)
train_data_file.close() # train_data_file.close()
def predictSamples(audio): def predictSamples(audio):
prob=model.predict(audio.reshape(1,8000,1)) prob=model.predict(audio.reshape(1,8000,1))
......
...@@ -128,12 +128,15 @@ def train(): ...@@ -128,12 +128,15 @@ def train():
pickle.dump(file=all_labels_file, obj=all_label) pickle.dump(file=all_labels_file, obj=all_label)
all_labels_file.close() all_labels_file.close()
return False
all_waves_file = open('all_waves_file.txt', 'wb+') all_waves_file = open('all_waves_file.txt', 'wb+')
pickle.dump(file=all_waves_file, obj=all_wave) pickle.dump(file=all_waves_file, obj=all_wave)
all_waves_file.close() all_waves_file.close()
print('Done: creating labels and waves files') print('Done: creating labels and waves files')
return False
le = LabelEncoder() le = LabelEncoder()
y = le.fit_transform(all_label) y = le.fit_transform(all_label)
classes = list(le.classes_) classes = list(le.classes_)
......
...@@ -26,7 +26,6 @@ from .model.predict import predict ...@@ -26,7 +26,6 @@ from .model.predict import predict
from pydub import AudioSegment from pydub import AudioSegment
import numpy as np import numpy as np
class UserViewSet(viewsets.ModelViewSet): class UserViewSet(viewsets.ModelViewSet):
""" """
API endpoint that allows users to be viewed or edited. API endpoint that allows users to be viewed or edited.
...@@ -80,7 +79,8 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -80,7 +79,8 @@ class MlModelViewSet(viewsets.ViewSet):
with open("output.m4a", "wb") as f: with open("output.m4a", "wb") as f:
f.write(bytesio_object.getbuffer()) f.write(bytesio_object.getbuffer())
path = os.path.abspath("output.m4a")
print(path)
# convert wav to mp3 # convert wav to mp3
audSeg = AudioSegment.from_file("output.m4a") audSeg = AudioSegment.from_file("output.m4a")
audSeg.export('output.wav', format="wav") audSeg.export('output.wav', format="wav")
...@@ -97,7 +97,7 @@ class MlModelViewSet(viewsets.ViewSet): ...@@ -97,7 +97,7 @@ class MlModelViewSet(viewsets.ViewSet):
print(samples.shape) print(samples.shape)
else: else:
len = 8000 - samples.shape[0] len = 8000 - samples.shape[0]
new_arr = np.zeroes(len, ) new_arr = np.zeros(len, )
samples = np.concatenate((samples, new_arr)) samples = np.concatenate((samples, new_arr))
print(samples.shape) print(samples.shape)
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment