Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sachith Fernando
2020-101
Commits
c32dcf59
Commit
c32dcf59
authored
Jan 10, 2021
by
I.K Seneviratne
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'IT17100908' into 'QA_RELEASE'
It17100908 See merge request
!49
parents
f4b30584
74fc015b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
153 additions
and
30 deletions
+153
-30
LectureSummarizingApp/ExtractKeySentences.py
LectureSummarizingApp/ExtractKeySentences.py
+19
-5
LectureSummarizingApp/Summary.py
LectureSummarizingApp/Summary.py
+7
-1
LectureSummarizingApp/api.py
LectureSummarizingApp/api.py
+31
-11
LectureSummarizingApp/lecture_audio_batch_process.py
LectureSummarizingApp/lecture_audio_batch_process.py
+73
-0
LectureSummarizingApp/noise.py
LectureSummarizingApp/noise.py
+9
-4
LectureSummarizingApp/speech_to_text.py
LectureSummarizingApp/speech_to_text.py
+6
-1
LectureSummarizingApp/templates/LectureSummarizingApp/summarization.html
...ingApp/templates/LectureSummarizingApp/summarization.html
+4
-4
LectureSummarizingApp/urls.py
LectureSummarizingApp/urls.py
+3
-3
LectureSummarizingApp/voice_recorder.py
LectureSummarizingApp/voice_recorder.py
+1
-1
No files found.
LectureSummarizingApp/ExtractKeySentences.py
View file @
c32dcf59
...
...
@@ -2,17 +2,26 @@ import nltk
import
os
from
fpdf
import
FPDF
def
LectureNotice
(
notice_name
):
def
Get
LectureNotice
(
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
LectureSummarizingApp/Summary.py
View file @
c32dcf59
...
...
@@ -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
LectureSummarizingApp/api.py
View file @
c32dcf59
...
...
@@ -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
ge
t
(
self
,
request
):
def
pos
t
(
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
a
udioNoiseRemovedList
(
APIView
):
class
A
udioNoiseRemovedList
(
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
a
udioToTextList
(
APIView
):
class
A
udioToTextList
(
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
})
...
...
LectureSummarizingApp/lecture_audio_batch_process.py
0 → 100644
View file @
c32dcf59
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
LectureSummarizingApp/noise.py
View file @
c32dcf59
...
...
@@ -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
)
LectureSummarizingApp/speech_to_text.py
View file @
c32dcf59
...
...
@@ -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
LectureSummarizingApp/templates/LectureSummarizingApp/summarization.html
View file @
c32dcf59
...
...
@@ -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"-->
...
...
LectureSummarizingApp/urls.py
View file @
c32dcf59
...
...
@@ -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
.
a
udioNoiseRemovedList
.
as_view
()),
url
(
r'^lecture-audio-noise-removed/$'
,
api
.
A
udioNoiseRemovedList
.
as_view
()),
url
(
r'^lecture-audio-to-text/
'
,
api
.
a
udioToTextList
.
as_view
()),
url
(
r'^lecture-audio-to-text/
$'
,
api
.
A
udioToTextList
.
as_view
()),
url
(
r'^lecture-summary/$'
,
api
.
LectureSummaryList
.
as_view
()),
...
...
LectureSummarizingApp/
Voice R
ecorder.py
→
LectureSummarizingApp/
voice_r
ecorder.py
View file @
c32dcf59
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment