Commit fd544989 authored by I.K Seneviratne's avatar I.K Seneviratne

Merge remote-tracking branch 'origin/QA_RELEASE' into monitoring_student_behavior_IT17138000

parents 37759908 c32dcf59
......@@ -2,17 +2,26 @@ import nltk
import os
from fpdf import FPDF
def LectureNotice(notice_name):
def GetLectureNotice(notice_name):
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
FILE_PATH = os.path.join(BASE_DIR, "speechToText\\{}".format(notice_name))
DESTINATION_DIR = os.path.join(BASE_DIR, "notices\\Notice_{}".format(notice_name))
print('destination directory: ', DESTINATION_DIR)
print('starting the notice process')
text = ''
read_lines = [line.rstrip('\n') for line in open(FILE_PATH, "r")]
# read_lines = [line.rstrip('\n') for line in open(FILE_PATH, "r")]
# read_lines = [line.rstrip('\n') for line in open(FILE_PATH, "r")]
for line in open(FILE_PATH, "r"):
text += line.rstrip('\n')
sentences_list = []
sentence_list = nltk.sent_tokenize(read_lines)
sentence_list = nltk.sent_tokenize(text)
word_search = "important"
sentences_with_word = []
for sentence in sentence_list:
......@@ -55,6 +64,11 @@ def LectureNotice(notice_name):
pdf.cell(200, 10, txt=x, ln=1, align='C')
# save the pdf with name .pdf
pdf.output("PDF_DESTINATION_DIR")
# pdf.output("PDF_DESTINATION_DIR")
listToStr = ' '.join([str(elem) for elem in sentences_with_word])
print('ending the notice process')
return text
\ No newline at end of file
return text, listToStr
\ No newline at end of file
......@@ -8,9 +8,13 @@ def LectureSummary(summary_name):
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
FILE_PATH = os.path.join(BASE_DIR, "speechToText\\{}".format(summary_name))
print('file path: ' , FILE_PATH)
DESTINATION_DIR = os.path.join(BASE_DIR, "summary\\Summary_{}".format(summary_name))
print('destination directory: ', DESTINATION_DIR)
print('starting the summary process')
# Reading the file
nlp = pt_core_news_sm.load()
# file = open(DESTINATION_DIR, 'w')
......@@ -87,9 +91,11 @@ def LectureSummary(summary_name):
pdf.cell(200, 10, txt=x, ln=1, align='C')
# save the pdf with name .pdf
pdf.output(PDF_DESTINATION_DIR)
# pdf.output(PDF_DESTINATION_DIR)
# convert the summary list to a text
listToStr = ' '.join([str(elem) for elem in summary])
print('ending the summary process')
return text, listToStr
\ No newline at end of file
......@@ -14,21 +14,41 @@ import datetime
# APIs used in Lecture Summarizing Component
from .ExtractKeySentences import GetLectureNotice
from .Summary import LectureSummary
from .noise import noise_removal
from .speech_to_text import speech_to_text
from .voice_recorder import AudioRecorder
class LectureAudioAPI(APIView):
def get(self, request):
def post(self, request):
lecture_audio = LectureAudio.objects.all().order_by('lecturer_date')
lecture_audio_serializer = LectureAudioSerializer(lecture_audio, many=True)
return Response(lecture_audio_serializer.data)
audio_list = LectureAudio.objects.order_by('lecture_audio_id').last()
audio_name = request.data['audio_name']
# id = int(request.query_params.get("id"))
new_audio_id = generate_new_id(audio_list.lecture_audio_noise_removed_id)
fake_duration = datetime.timedelta(minutes=00, seconds=10, milliseconds=00)
AudioRecorder(audio_name)
LectureAudio(
lecture_audio_id=new_audio_id,
lecture_audio_name =audio_name,
lecture_audio_length = fake_duration,
lecturer =request.data["lecturer"],
subject = request.data["subject"]
).save()
return Response({
"response": Response.status_code
})
class audioNoiseRemovedList(APIView):
class AudioNoiseRemovedList(APIView):
def get(self, request):
# lecture_audio_noise_removed = LectureAudioNoiseRemoved.objects.all()
......@@ -48,7 +68,7 @@ class audioNoiseRemovedList(APIView):
# nr.noise_removalll(video_name)
noise_removal(audio_name)
a, sr = noise_removal(audio_name)
LectureAudioNoiseRemoved(
lecture_audio_noise_removed_id=new_audio_noise_removed_id,
......@@ -73,7 +93,7 @@ class audioNoiseRemovedList(APIView):
return Response({"response": request.data})
class audioToTextList(APIView):
class AudioToTextList(APIView):
def get(self, request):
#lecture_speech_to_text_id = LectureSpeechToText.objects.all()
......@@ -89,9 +109,9 @@ class audioToTextList(APIView):
# generate new id for speech to text file
new_speech_to_text_id = generate_new_id(audio_to_text_list.lecture_speech_to_text_id)
new_speech_to_text_id = "LST0001" if audio_to_text_list is None else generate_new_id(audio_to_text_list.lecture_speech_to_text_id)
speech_to_text(speech_to_text_name)
is_finished = speech_to_text(speech_to_text_name)
LectureSpeechToText(
lecture_speech_to_text_id=new_speech_to_text_id,
......@@ -135,7 +155,7 @@ class LectureSummaryList(APIView):
audio_original_text=text,
audio_summary=summary
).save()
return Response({"response": request.data})
return Response({"response": Response.status_code})
def post(self, request):
LectureAudioSummary(
......@@ -163,14 +183,14 @@ class LectureNoticeList(APIView):
# generate new id for notice
notice_id = "LN0001" if lecture_notice_list is None else generate_new_id(lecture_notice_list.lecture_notice_id)
text = LectureNotices(lecture_notice_name)
text, sentences_with_word = GetLectureNotice(lecture_notice_name)
LectureNotices(
lecture_notice_id=notice_id,
lecture_audio_id=id,
lecture_audio_id_id=id,
notice_text=text
).save()
return Response({"response": request.data})
return Response({"response": Response.status_code})
......
import json
import requests
# this method calls all the summarization methods in one place
def summarization_batch_process(audio_id, audio_name):
is_all_processed = False
noise_removed_resp = requests.get('http://127.0.0.1:8000/summary/lecture-audio-noise-removed/', params={'id': audio_id, 'audio_name': audio_name})
print('response: ', noise_removed_resp.json())
if noise_removed_resp.json()['response'] == 200:
print('successful noise removed response')
audio_root_name = audio_name.split('.')[0]
speech_to_text_name = audio_root_name + '.txt'
audio_text_resp = requests.get('http://127.0.0.1:8000/summary/lecture-audio-to-text/', params={'id': audio_id, 'speech_to_text_name': speech_to_text_name})
if audio_text_resp.json()['response'] == 200:
print('successful audio to text response')
summary_name = audio_name + '.txt'
summary_resp = requests.get('http://127.0.0.1:8000/summary/lecture-summary/', params={'id': audio_id, 'lecture_summary_name': summary_name})
if summary_resp.json()['response'] == 200:
print('successful summary response')
notice_resp = requests.get('http://127.0.0.1:8000/summary/lecture-notices/', params={'id': audio_id, 'lecture_notice_name': summary_name})
if notice_resp.json()['response'] == 200:
print('successful notice response')
is_all_processed = True
return is_all_processed
def save_lecturer_audio(lecturer_audio):
data_dumps = json.dumps(lecturer_audio)
response = None
headers = {
'Content-Type': 'application/json'
}
# call the API
# student_video_save_resp = requests.post('http://127.0.0.1:8000/lecture-video', student_video)
lecturer_audio_save_resp = requests.post(url='http://127.0.0.1:8000/summary/lecture-audio', data=data_dumps, headers=headers)
data = lecturer_audio_save_resp.json()
response = data[0]
return response
# # this is a test method (delete later)
# if __name__ == '__main__':
# audio_id = 1
# audio_name = 'Lecture01.wav'
#
# summarization_batch_process(audio_id=audio_id, audio_name=audio_name)
\ No newline at end of file
......@@ -10,12 +10,14 @@ def noise_removal(video_name):
# sample_directory = 'lectures/'
# sample_path = sample_directory + sample_file
print('starting the noise removal process')
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LECTURE_VIDEO_DIR = os.path.join(BASE_DIR, "LectureSummarizingApp\\lectures\\{}".format(video_name))
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
LECTURE_VIDEO_DIR = os.path.join(BASE_DIR, "lectures\\{}".format(video_name))
print('lecture audio directory: ', LECTURE_VIDEO_DIR)
# DESTINATION_DIR = os.path.join(BASE_DIR, "LectureSummarizingApp\\noise_removed_lectures")
DESTINATION_DIR = os.path.dirname(os.path.join(BASE_DIR, "LectureSummarizingApp\\noise_removed_lectures\\sample.txt"))
DESTINATION_DIR = os.path.dirname(os.path.join(BASE_DIR, "noise_removed_lectures\\sample.txt"))
print('destination directory: ', DESTINATION_DIR)
# generating audio time series and a sampling rate (int)
a, sr = librosa.load(path=LECTURE_VIDEO_DIR)
......@@ -27,6 +29,8 @@ def noise_removal(video_name):
output_file(destination=DESTINATION_DIR, filename=video_name, a=a, sr=sr)
print('ending the noise removal process')
return a, sr
......@@ -75,6 +79,7 @@ def mffc_highshelf(a, sr):
# return a_enhanced
def output_file(destination ,filename, a, sr, ext=""):
destination = destination + filename[:-4] + ext + '.wav'
destination = destination + "\\" + filename[:-4] + ext + '.wav'
print('output destination: ', destination)
librosa.output.write_wav(destination, a, sr)
......@@ -4,6 +4,7 @@ import os
def speech_to_text(speech_to_text_name):
print('starting the speech_to_text process')
#calling the Recognizer()
r = sr.Recognizer()
......@@ -25,4 +26,8 @@ def speech_to_text(speech_to_text_name):
except:
file.write('error')
file.close()
\ No newline at end of file
file.close()
print('ending the speech_to_text process')
return True
......@@ -86,8 +86,8 @@
$('.to_summary').click(function(e) {
alert('Processing');
let id = e.target.parentNode.parentNode.getAttribute('id');
<!-- let lecture_summary_name = e.target.parentNode.parentNode.getAttribute('data-summary-name');-->
let lecture_summary_name = e.target.parentNode.parentNode.getAttribute('data-notice-name');
let lecture_summary_name = e.target.parentNode.parentNode.getAttribute('data-summary-name');
<!-- let lecture_summary_name = e.target.parentNode.parentNode.getAttribute('data-notice-name');-->
<!-- lecture_summary_name = lecture_summary_name + ".txt";-->
lecture_summary_name = lecture_summary_name + ".wav.txt";
alert('id: ' + id);
......@@ -112,7 +112,7 @@
$('.get_notices').click(function(e) {
alert('Processing');
let id = e.target.parentNode.parentNode.getAttribute('id');
let lecture_notice_name = e.target.parentNode.parentNode.getAttribute('data-summary-name');
let lecture_notice_name = e.target.parentNode.parentNode.getAttribute('data-notice-name');
lecture_notice_name = lecture_notice_name + ".wav.txt";
alert('id: ' + id);
alert('lecture_notice_name: ' + lecture_notice_name);
......@@ -311,7 +311,7 @@
<tbody>
{% for lec_text in lecture_text_data %}
<tr class="recordings not_clicked" id="{{ lec_text.lecture_audio_id.id }}" data-summary-name="{{lec_text.lecture_audio_id.lecture_audio_name}}" data-notice-name="{{lec_text.lecture_audio_id}}" >
<tr class="recordings not_clicked" id="{{ lec_text.lecture_audio_id.id }}" data-summary-name="{{lec_text.lecture_audio_id.lecture_audio_name}}" data-notice-name="{{lec_text.lecture_audio_id.lecture_audio_name}}" >
<!-- <td>-->
<!-- <div class="radio">-->
<!-- <label><input type="radio"-->
......
......@@ -12,11 +12,11 @@ urlpatterns = [
# API to retrieve lecture summarizing details
url(r'^lecture-audio/$', api.LectureAudioAPI.as_view()),
url(r'^lecture-audio', api.LectureAudioAPI.as_view()),
url(r'^lecture-audio-noise-removed/$', api.audioNoiseRemovedList.as_view()),
url(r'^lecture-audio-noise-removed/$', api.AudioNoiseRemovedList.as_view()),
url(r'^lecture-audio-to-text/', api.audioToTextList.as_view()),
url(r'^lecture-audio-to-text/$', api.AudioToTextList.as_view()),
url(r'^lecture-summary/$', api.LectureSummaryList.as_view()),
......
......@@ -12,7 +12,7 @@ def AudioRecorder(audio):
DESTINATION_DIR = os.path.join(BASE_DIR, "audioArray\\{}".format(audio))
#for the audio
LECTURE_AUDIO_DIR = os.path.join(BASE_DIR, "lectures\\Lecture_{}".format(audio))
LECTURE_AUDIO_DIR = os.path.join(BASE_DIR, "lectures\\{}".format(audio))
# Sampling frequency
......
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