Commit 010d9235 authored by LiniEisha's avatar LiniEisha

Integrate

parent e2c05f52
...@@ -28,6 +28,9 @@ def LectureNotice(notice_name): ...@@ -28,6 +28,9 @@ def LectureNotice(notice_name):
sentences_with_word.append(sentence) sentences_with_word.append(sentence)
word_sentence_dictionary[word] = sentences_with_word word_sentence_dictionary[word] = sentences_with_word
file = open('Notices01.txt', 'w')
file.close()
def SaveNotices(): def SaveNotices():
pdf = FPDF() pdf = FPDF()
......
...@@ -6,14 +6,16 @@ from fpdf import FPDF ...@@ -6,14 +6,16 @@ from fpdf import FPDF
def LectureSummary(summary_name): def LectureSummary(summary_name):
# BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# FILE_PATH = os.path.join(BASE_DIR, "speechToText\\{}".format(summary_name)) FILE_PATH = os.path.join(BASE_DIR, "speechToText\\{}".format(summary_name))
# DESTINATION_DIR = os.path.dirname(os.path.join(BASE_DIR, "LectureSummarizingApp\\summary\\sample.txt")) DESTINATION_DIR = os.path.join(BASE_DIR, "summary\\Summary_{}".format(summary_name))
# print('destination directory: ', DESTINATION_DIR) print('destination directory: ', DESTINATION_DIR)
# Reading the file # Reading the file
nlp = pt_core_news_sm.load() nlp = pt_core_news_sm.load()
with open("audioToText.txt", "r", encoding="utf-8") as f: # file = open(DESTINATION_DIR, 'w')
text = ''
with open(FILE_PATH, "r", encoding="utf-8") as f:
text = " ".join(f.readlines()) text = " ".join(f.readlines())
doc = nlp(text) doc = nlp(text)
...@@ -53,13 +55,23 @@ def LectureSummary(summary_name): ...@@ -53,13 +55,23 @@ def LectureSummary(summary_name):
summary.append(sent) summary.append(sent)
else: else:
continue continue
file = None
for i in summary: for i in summary:
file = open('Summary01.txt', 'w') file = open(DESTINATION_DIR, 'w')
# file = open('Summary01.txt', 'w')
file.write(str(i)) file.write(str(i))
file.close() file.close()
def SaveSummary():
# def SaveSummary():
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# PDF_DESTINATION_DIR = os.path.dirname(os.path.join(BASE_DIR, "summaryPDF\\sample.txt"))
PDF_DESTINATION_DIR = os.path.join(BASE_DIR, "summaryPDF\\Summary_PDF_{}.pdf".format(summary_name))
pdf = FPDF() pdf = FPDF()
# Add a page # Add a page
pdf.add_page() pdf.add_page()
...@@ -68,11 +80,16 @@ def SaveSummary(): ...@@ -68,11 +80,16 @@ def SaveSummary():
pdf.set_font("Arial", size=15) pdf.set_font("Arial", size=15)
# open the text file in read mode # open the text file in read mode
f = open("Summary01.txt", "r") f = open(DESTINATION_DIR, "r")
# insert the texts in pdf # insert the texts in pdf
for x in f: for x in f:
pdf.cell(200, 10, txt=x, ln=1, align='C') pdf.cell(200, 10, txt=x, ln=1, align='C')
# save the pdf with name .pdf # save the pdf with name .pdf
pdf.output("summary01.pdf") pdf.output(PDF_DESTINATION_DIR)
\ No newline at end of file
# convert the summary list to a text
listToStr = ' '.join([str(elem) for elem in summary])
return text, listToStr
\ No newline at end of file
...@@ -14,6 +14,7 @@ import datetime ...@@ -14,6 +14,7 @@ import datetime
# APIs used in Lecture Summarizing Component # APIs used in Lecture Summarizing Component
from .Summary import LectureSummary
from .noise import noise_removal from .noise import noise_removal
from .speech_to_text import speech_to_text from .speech_to_text import speech_to_text
...@@ -83,15 +84,17 @@ class audioToTextList(APIView): ...@@ -83,15 +84,17 @@ class audioToTextList(APIView):
print('file name: ', speech_to_text_name) print('file name: ', speech_to_text_name)
id = int(request.query_params.get("id")) id = int(request.query_params.get("id"))
# id = request.query_params.get("id")
# generate new id for speech to text file # generate new id for speech to text file
new_speech_to_text_id = generate_new_id(audio_to_text_list.new_speech_to_text_id) new_speech_to_text_id = generate_new_id(audio_to_text_list.lecture_speech_to_text_id)
speech_to_text(speech_to_text_name) speech_to_text(speech_to_text_name)
LectureSpeechToText( LectureSpeechToText(
lecture_speech_to_text_id=new_speech_to_text_id, lecture_speech_to_text_id=new_speech_to_text_id,
lecture_audio_id=id, lecture_audio_id_id=id,
audio_original_text=speech_to_text_name audio_original_text=speech_to_text_name
).save() ).save()
...@@ -108,29 +111,29 @@ class audioToTextList(APIView): ...@@ -108,29 +111,29 @@ class audioToTextList(APIView):
return Response({"response": request.data}) return Response({"response": request.data})
class lectureSummaryList(APIView): class LectureSummaryList(APIView):
def get(self, request): def get(self, request):
lecture_audio_summary_id = LectureAudioSummary.objects.all() lecture_audio_summary_id = LectureAudioSummary.objects.all()
# serializer = LectureAudioSummarySerializer(lecture_audio_summary_id, many=True) # serializer = LectureAudioSummarySerializer(lecture_audio_summary_id, many=True)
# return Response(serializer.data) # return Response(serializer.data)
lecture_summary_list = LectureAudioSummary.objects.order_by('lecture_summary_list').last() lecture_summary_list = LectureAudioSummary.objects.order_by('lecture_audio_summary_id').last()
lecture_summary_name = request.query_params.get("lecture_summary_name") lecture_summary_name = request.query_params.get("lecture_summary_name")
id = int(request.query_params.get("id")) id = int(request.query_params.get("id"))
current_date = datetime.datetime.now().date() current_date = datetime.datetime.now().date()
# generate new id for summary # generate new id for summary
lecture_summary_id = generate_new_id(lecture_summary_list.lecture_summary_id) lecture_summary_id = "LSUM0001" if lecture_summary_list is None else generate_new_id(lecture_summary_list.lecture_audio_summary_id)
LectureAudioSummary(lecture_summary_name) text, summary = LectureSummary(lecture_summary_name)
LectureAudioSummary( LectureAudioSummary(
lecture_speech_to_text_id=id, lecture_audio_summary_id=lecture_summary_id,
lecture_audio_id=lecture_summary_id, lecture_audio_id_id=id,
audio_original_text=current_date, audio_original_text=text,
audio_summary=lecture_summary_name audio_summary=summary
).save() ).save()
return Response({"response": request.data}) return Response({"response": request.data})
......
...@@ -8,13 +8,17 @@ def speech_to_text(speech_to_text_name): ...@@ -8,13 +8,17 @@ def speech_to_text(speech_to_text_name):
r = sr.Recognizer() r = sr.Recognizer()
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# FILE_PATH = os.path.join(BASE_DIR, "noise_removed_lectures\\noise_removed_lectures_{}".format(speech_to_text_name))
FILE_PATH = os.path.join(BASE_DIR, "noise_removed_lectures\\{}".format(speech_to_text_name)) FILE_PATH = os.path.join(BASE_DIR, "noise_removed_lectures\\{}".format(speech_to_text_name))
DESTINATION_DIR = os.path.dirname(os.path.join(BASE_DIR, "LectureSummarizingApp\\speechToText\\sample.txt")) print('file path: ', FILE_PATH)
# DESTINATION_DIR = os.path.dirname(os.path.join(BASE_DIR, "LectureSummarizingApp\\speechToText\\{}.txt".format(speech_to_text_name)))
DESTINATION_DIR = os.path.join(BASE_DIR, "speechToText\\{}.txt".format(speech_to_text_name))
print('destination directory: ', DESTINATION_DIR) print('destination directory: ', DESTINATION_DIR)
with sr.AudioFile(FILE_PATH) as source: with sr.AudioFile(FILE_PATH) as source:
audio = r.listen(source) audio = r.listen(source)
file = open('audioToText01.txt', 'w') #open file # file = open('audioToText01.txt', 'w') #open file
file = open(DESTINATION_DIR, 'w') #open file
try: try:
text = r.recognize_google(audio) #Convert using google recognizer text = r.recognize_google(audio) #Convert using google recognizer
file.write(text) file.write(text)
......
...@@ -35,11 +35,12 @@ ...@@ -35,11 +35,12 @@
$(document).ready(function() { $(document).ready(function() {
<!-- speech to text--> <!-- speech to text-->
$('.audio_to_text_process').click(function() { $('.audio_to_text_process').click(function(e) {
alert('Processing'); alert('Converting');
let id = e.target.parentNode.parentNode.getAttribute('id'); let id = e.target.parentNode.parentNode.getAttribute('id');
let speech_to_text_name = e.target.parentNode.parentNode.getAttribute('data-noiseless-audio-name'); let speech_to_text_name = e.target.parentNode.parentNode.getAttribute('data-noiseless-audio-name');
speech_to_text_name = speech_to_text_name + ".txt"; <!-- speech_to_text_name = speech_to_text_name + ".txt";-->
alert('id: ' + id); alert('id: ' + id);
alert('speech to text file name: ' + speech_to_text_name); alert('speech to text file name: ' + speech_to_text_name);
...@@ -82,17 +83,18 @@ ...@@ -82,17 +83,18 @@
} }
<!-- To summary--> <!-- To summary-->
$('.to_summary').click(function() { $('.to_summary').click(function(e) {
alert('Processing'); alert('Processing');
let id = e.target.parentNode.parentNode.getAttribute('id'); 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-summary-name');
lecture_summary_name = lecture_summary_name + ".wav"; <!-- lecture_summary_name = lecture_summary_name + ".txt";-->
lecture_summary_name = lecture_summary_name + ".wav.txt";
alert('id: ' + id); alert('id: ' + id);
alert('lecture_summary_name: ' + lecture_summary_name); alert('lecture_summary_name: ' + lecture_summary_name);
//call the fetch API //call the fetch API
etch('http://127.0.0.1:8000/summary/lecture-summary/?lecture_summary_name=' + lecture_summary_name + '&id=' + id) fetch('http://127.0.0.1:8000/summary/lecture-summary/?lecture_summary_name=' + lecture_summary_name + '&id=' + id)
.then((res) => res.json()) .then((res) => res.json())
.then((out) => handleLectureRemoved(out.response)) .then((out) => handleLectureRemoved(out.response))
.catch((err) => alert('error: ' + err)) .catch((err) => alert('error: ' + err))
...@@ -106,7 +108,7 @@ ...@@ -106,7 +108,7 @@
} }
<!-- To Notice--> <!-- To Notice-->
$('.get_notices').click(function() { $('.get_notices').click(function(e) {
alert('Processing'); alert('Processing');
let id = e.target.parentNode.parentNode.getAttribute('id'); 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-summary-name');
...@@ -116,7 +118,7 @@ ...@@ -116,7 +118,7 @@
//call the fetch API //call the fetch API
etch('http://127.0.0.1:8000/summary/lecture-notices/?lecture_notice_name=' + lecture_notice_name + '&id=' + id) fetch('http://127.0.0.1:8000/summary/lecture-notices/?lecture_notice_name=' + lecture_notice_name + '&id=' + id)
.then((res) => res.json()) .then((res) => res.json())
.then((out) => handleNoticeRemoved(out.response)) .then((out) => handleNoticeRemoved(out.response))
.catch((err) => alert('error: ' + err)) .catch((err) => alert('error: ' + err))
...@@ -240,7 +242,7 @@ ...@@ -240,7 +242,7 @@
<tbody> <tbody>
{% for noiseless_audio in noiseless_data %} {% for noiseless_audio in noiseless_data %}
<tr class="recordings not_clicked" id="{{ noiseless_audio.lecture_audio_id }}" data-noiseless-audio-name="{{ noiseless_audio.lecture_audio_name }}"> <tr class="recordings not_clicked" id="{{ noiseless_audio.lecture_audio_id.id }}" data-noiseless-audio-name="{{ noiseless_audio.lecture_audio_name }}">
<!-- <td>--> <!-- <td>-->
<!-- <div class="radio">--> <!-- <div class="radio">-->
<!-- <label><input type="radio"--> <!-- <label><input type="radio"-->
...@@ -308,7 +310,7 @@ ...@@ -308,7 +310,7 @@
<tbody> <tbody>
{% for lec_text in lecture_text_data %} {% for lec_text in lecture_text_data %}
<tr class="recordings not_clicked" id="{{ lec_text.lecture_audio_id }}" data-summary-name="{{lec_text.lecture_audio_id.subject.name}}"> <tr class="recordings not_clicked" id="{{ lec_text.lecture_audio_id.id }}" data-summary-name="{{lec_text.lecture_audio_id.lecture_audio_name}}">
<!-- <td>--> <!-- <td>-->
<!-- <div class="radio">--> <!-- <div class="radio">-->
<!-- <label><input type="radio"--> <!-- <label><input type="radio"-->
......
...@@ -18,7 +18,7 @@ urlpatterns = [ ...@@ -18,7 +18,7 @@ urlpatterns = [
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()), url(r'^lecture-summary/$', api.LectureSummaryList.as_view()),
url(r'^lecture-notices/$', api.lectureNoticeList.as_view()), url(r'^lecture-notices/$', api.lectureNoticeList.as_view()),
......
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