Commit 010d9235 authored by LiniEisha's avatar LiniEisha

Integrate

parent e2c05f52
......@@ -28,6 +28,9 @@ def LectureNotice(notice_name):
sentences_with_word.append(sentence)
word_sentence_dictionary[word] = sentences_with_word
file = open('Notices01.txt', 'w')
file.close()
def SaveNotices():
pdf = FPDF()
......
......@@ -6,14 +6,16 @@ from fpdf import FPDF
def LectureSummary(summary_name):
# BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# 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"))
# print('destination directory: ', DESTINATION_DIR)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
FILE_PATH = os.path.join(BASE_DIR, "speechToText\\{}".format(summary_name))
DESTINATION_DIR = os.path.join(BASE_DIR, "summary\\Summary_{}".format(summary_name))
print('destination directory: ', DESTINATION_DIR)
# Reading the file
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())
doc = nlp(text)
......@@ -53,13 +55,23 @@ def LectureSummary(summary_name):
summary.append(sent)
else:
continue
file = None
for i in summary:
file = open('Summary01.txt', 'w')
file = open(DESTINATION_DIR, 'w')
# file = open('Summary01.txt', 'w')
file.write(str(i))
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()
# Add a page
pdf.add_page()
......@@ -68,11 +80,16 @@ def SaveSummary():
pdf.set_font("Arial", size=15)
# open the text file in read mode
f = open("Summary01.txt", "r")
f = open(DESTINATION_DIR, "r")
# insert the texts in pdf
for x in f:
pdf.cell(200, 10, txt=x, ln=1, align='C')
# save the pdf with name .pdf
pdf.output("summary01.pdf")
\ No newline at end of file
pdf.output(PDF_DESTINATION_DIR)
# 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
# APIs used in Lecture Summarizing Component
from .Summary import LectureSummary
from .noise import noise_removal
from .speech_to_text import speech_to_text
......@@ -83,15 +84,17 @@ class audioToTextList(APIView):
print('file name: ', speech_to_text_name)
id = int(request.query_params.get("id"))
# id = request.query_params.get("id")
# 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)
LectureSpeechToText(
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
).save()
......@@ -108,29 +111,29 @@ class audioToTextList(APIView):
return Response({"response": request.data})
class lectureSummaryList(APIView):
class LectureSummaryList(APIView):
def get(self, request):
lecture_audio_summary_id = LectureAudioSummary.objects.all()
# serializer = LectureAudioSummarySerializer(lecture_audio_summary_id, many=True)
# 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")
id = int(request.query_params.get("id"))
current_date = datetime.datetime.now().date()
# 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(
lecture_speech_to_text_id=id,
lecture_audio_id=lecture_summary_id,
audio_original_text=current_date,
audio_summary=lecture_summary_name
lecture_audio_summary_id=lecture_summary_id,
lecture_audio_id_id=id,
audio_original_text=text,
audio_summary=summary
).save()
return Response({"response": request.data})
......
......@@ -8,13 +8,17 @@ def speech_to_text(speech_to_text_name):
r = sr.Recognizer()
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))
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)
with sr.AudioFile(FILE_PATH) as 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:
text = r.recognize_google(audio) #Convert using google recognizer
file.write(text)
......
......@@ -35,11 +35,12 @@
$(document).ready(function() {
<!-- speech to text-->
$('.audio_to_text_process').click(function() {
alert('Processing');
$('.audio_to_text_process').click(function(e) {
alert('Converting');
let id = e.target.parentNode.parentNode.getAttribute('id');
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('speech to text file name: ' + speech_to_text_name);
......@@ -82,17 +83,18 @@
}
<!-- To summary-->
$('.to_summary').click(function() {
$('.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');
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('lecture_summary_name: ' + lecture_summary_name);
//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((out) => handleLectureRemoved(out.response))
.catch((err) => alert('error: ' + err))
......@@ -106,7 +108,7 @@
}
<!-- To Notice-->
$('.get_notices').click(function() {
$('.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');
......@@ -116,7 +118,7 @@
//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((out) => handleNoticeRemoved(out.response))
.catch((err) => alert('error: ' + err))
......@@ -240,7 +242,7 @@
<tbody>
{% 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>-->
<!-- <div class="radio">-->
<!-- <label><input type="radio"-->
......@@ -308,7 +310,7 @@
<tbody>
{% 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>-->
<!-- <div class="radio">-->
<!-- <label><input type="radio"-->
......
......@@ -18,7 +18,7 @@ urlpatterns = [
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()),
......
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