Commit 3e85b92f authored by I.K Seneviratne's avatar I.K Seneviratne

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

parents 110d8995 c217af8f
......@@ -23,7 +23,7 @@ maskNet = load_model(os.path.join(settings.BASE_DIR,'face_detector/mask_detector
class IPWebCam(object):
def __init__(self):
self.url = "http://192.168.8.103:8080/shot.jpg"
self.url = "http://192.168.8.100:8080/shot.jpg"
def __del__(self):
cv2.destroyAllWindows()
......
......@@ -55,6 +55,13 @@ function testAPI() {
.then((out) => {})
.catch((err) => alert('error: ' + err));
//audio
var audio_name = 'Lecture';
fetch('http://127.0.0.1:8000/summary/lecture-audio/?audio_name=' + audio_name)
then((res) => res.json())
.then((out) => {})
.catch((err) => alert('error: ' + err));
}
var time = 'time';
function f() {
......
......@@ -12,7 +12,7 @@ def IPWebcamTest():
# Replace the URL with your own IPwebcam shot.jpg IP:port
# url = 'http://192.168.2.35:8080/shot.jpg'
url = 'http://192.168.8.103:8080/shot.jpg'
url = 'http://192.168.8.100:8080/shot.jpg'
# url = 'http://192.168.1.11:8080/startvideo?force=1&tag=rec'
# url = 'http://192.168.1.11:8080/stopvideo?force=1'
......
......@@ -118,7 +118,7 @@
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<h6 class="collapse-header">Components:</h6>
<a class="collapse-item" href="/summary/record">Record Lecture</a>
<!-- <a class="collapse-item" href="/summary/record">Record Lecture</a>-->
<a class="collapse-item" href="/summary/lecture">Summarization</a>
</div>
</div>
......@@ -174,7 +174,7 @@
<div class="bg-white py-2 collapse-inner rounded">
<!-- <h6 class="collapse-header">Login Screens:</h6>-->
<a class="collapse-item" href="/lecturer">Dashboard</a>
<a class="collapse-item" href="/lecturer/lecture-video">Video Page</a>
<a class="collapse-item" href="/lecturer/lecture-video">Audio analysis Key-words.</a>
</div>
</div>
......
import nltk
read_lines = [line.rstrip('\n') for line in open("audioToText01.txt", "r")]
sentences_list = []
sentence_list = nltk.sent_tokenize(read_lines)
word_search = "important"
sentences_with_word = []
for sentence in sentences_list:
if sentence.count(word_search)>0:
sentences_with_word.append(sentence)
words_search = ["exam", "assignment"]
word_sentence_dictionary = {"exam":[],"assignment":[]}
for word in words_search:
import os
from fpdf import FPDF
def 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)
text = ''
read_lines = [line.rstrip('\n') for line in open(FILE_PATH, "r")]
sentences_list = []
sentence_list = nltk.sent_tokenize(read_lines)
word_search = "important"
sentences_with_word = []
for sentence in sentences_list:
if sentence.count(word)>0:
for sentence in sentence_list:
if sentence.count(word_search)>0:
sentences_with_word.append(sentence)
word_sentence_dictionary[word] = sentences_with_word
\ No newline at end of file
words_search = ["exam", "assignment"]
word_sentence_dictionary = {"exam":[],"assignment":[]}
for word in words_search:
sentences_with_word = []
for sentence in sentences_list:
if sentence.count(word)>0:
sentences_with_word.append(sentence)
word_sentence_dictionary[word] = sentences_with_word
file = open('DESTINATION_DIR', 'w')
file.close()
# def SaveNotices():
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, "noticePDF\\Notice{}.pdf".format(notice_name))
pdf = FPDF()
# Add a page
pdf.add_page()
# set style and size of font
# that you want in the pdf
pdf.set_font("Arial", size=15)
# open the text file in read mode
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("PDF_DESTINATION_DIR")
return text
\ No newline at end of file
from spacy.lang.pt.stop_words import STOP_WORDS
from sklearn.feature_extraction.text import CountVectorizer
import pt_core_news_sm
import os
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.join(BASE_DIR, "summary\\Summary_{}".format(summary_name))
print('destination directory: ', DESTINATION_DIR)
# Reading the file
nlp = pt_core_news_sm.load()
with open("audioToText01.txt", "r", encoding="utf-8") as f:
text = " ".join(f.readlines())
nlp = pt_core_news_sm.load()
# file = open(DESTINATION_DIR, 'w')
text = ''
with open(FILE_PATH, "r", encoding="utf-8") as f:
text = " ".join(f.readlines())
doc = nlp(text)
doc = nlp(text)
#calculating the word frequency
corpus = [sent.text.lower() for sent in doc.sents ]
cv = CountVectorizer(stop_words=list(STOP_WORDS))
cv_fit=cv.fit_transform(corpus)
word_list = cv.get_feature_names()
count_list = cv_fit.toarray().sum(axis=0)
word_frequency = dict(zip(word_list,count_list))
val=sorted(word_frequency.values())
higher_word_frequencies = [word for word,freq in word_frequency.items() if freq in val[-3:]]
print("\nWords with higher frequencies: ", higher_word_frequencies)
# gets relative frequency of words
higher_frequency = val[-1]
for word in word_frequency.keys():
word_frequency[word] = (word_frequency[word]/higher_frequency)
corpus = [sent.text.lower() for sent in doc.sents ]
cv = CountVectorizer(stop_words=list(STOP_WORDS))
cv_fit=cv.fit_transform(corpus)
word_list = cv.get_feature_names()
count_list = cv_fit.toarray().sum(axis=0)
word_frequency = dict(zip(word_list,count_list))
val=sorted(word_frequency.values())
higher_word_frequencies = [word for word,freq in word_frequency.items() if freq in val[-3:]]
print("\nWords with higher frequencies: ", higher_word_frequencies)
# gets relative frequency of words
higher_frequency = val[-1]
for word in word_frequency.keys():
word_frequency[word] = (word_frequency[word]/higher_frequency)
#calculating sentence rank and taking top ranked sentences for the summary
sentence_rank={}
for sent in doc.sents:
for word in sent :
if word.text.lower() in word_frequency.keys():
if sent in sentence_rank.keys():
sentence_rank[sent]+=word_frequency[word.text.lower()]
else:
sentence_rank[sent]=word_frequency[word.text.lower()]
top_sentences=(sorted(sentence_rank.values())[::-1])
top_sent=top_sentences[:3]
summary=[]
for sent,strength in sentence_rank.items():
if strength in top_sent:
summary.append(sent)
else:
continue
for i in summary:
file = open('Summary01.txt', 'w')
file.write(str(i))
file.close()
\ No newline at end of file
sentence_rank={}
for sent in doc.sents:
for word in sent :
if word.text.lower() in word_frequency.keys():
if sent in sentence_rank.keys():
sentence_rank[sent]+=word_frequency[word.text.lower()]
else:
sentence_rank[sent]=word_frequency[word.text.lower()]
top_sentences=(sorted(sentence_rank.values())[::-1])
top_sent=top_sentences[:3]
summary=[]
for sent,strength in sentence_rank.items():
if strength in top_sent:
summary.append(sent)
else:
continue
file = None
for i in summary:
file = open(DESTINATION_DIR, 'w')
# file = open('Summary01.txt', 'w')
file.write(str(i))
file.close()
# 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()
# set style and size of font
# that you want in the pdf
pdf.set_font("Arial", size=15)
# open the text file in read mode
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(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
import sounddevice as sd
from scipy.io.wavfile import write
import wavio as wv
import os
# Sampling frequency
freq = 44100
def AudioRecorder(audio):
# Recording duration
duration = 10
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Start recorder with the given values of
# duration and sample frequency
recording = sd.rec(int(duration * freq),
samplerate=freq, channels=2)
#for the array
DESTINATION_DIR = os.path.join(BASE_DIR, "audioArray\\{}".format(audio))
# Record audio for the given number of seconds
sd.wait()
#for the audio
LECTURE_AUDIO_DIR = os.path.join(BASE_DIR, "lectures\\Lecture_{}".format(audio))
# This will convert the NumPy array to an audio
# file with the given sampling frequency
write("recording0.wav", freq, recording)
# Sampling frequency
freq = 44100
#Convert the NumPy array to audio file
wv.write("recording1.wav", recording, freq, sampwidth=2)
\ No newline at end of file
# Recording duration
duration = 20
# Start recorder with the given values of
# duration and sample frequency
recording = sd.rec(int(duration * freq),samplerate=freq, channels=2)
# Record audio for the given number of seconds
sd.wait()
# This will convert the NumPy array to an audio
# file with the given sampling frequency
write(DESTINATION_DIR, freq, recording)
#Convert the NumPy array to audio file
wv.write(LECTURE_AUDIO_DIR, recording, freq, sampwidth=2)
\ No newline at end of file
from rest_framework.views import APIView
from rest_framework.response import Response
from FirstApp.logic.id_generator import generate_new_id
from LectureSummarizingApp.models import LectureAudio, LectureAudioNoiseRemoved, LectureSpeechToText, \
LectureAudioSummary, LectureNotices
from LectureSummarizingApp.serializer import LectureAudioSerializer, LectureAudioNoiseRemovedSerializer, \
LectureSpeechToTextSerializer, LectureAudioSummarySerializer, LectureNoticesSerializer
from . import speech_to_text as stt
from . import noiseRemove as nr
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
class LectureAudioAPI(APIView):
def get(self, request):
......@@ -18,12 +27,40 @@ class LectureAudioAPI(APIView):
return Response(lecture_audio_serializer.data)
class audioNoiseRemovedList(APIView):
def get(self, request):
lecture_audio_noise_removed = LectureAudioNoiseRemoved.objects.all()
serializer = LectureAudioNoiseRemovedSerializer(lecture_audio_noise_removed, many=True)
return Response(serializer.data)
# lecture_audio_noise_removed = LectureAudioNoiseRemoved.objects.all()
# serializer = LectureAudioNoiseRemovedSerializer(lecture_audio_noise_removed, many=True)
audio_noise_removed_list = LectureAudioNoiseRemoved.objects.order_by('lecture_audio_noise_removed_id').last()
audio_name = request.query_params.get("audio_name")
id = int(request.query_params.get("id"))
current_date = datetime.datetime.now().date()
fake_duration = datetime.timedelta(minutes=2, seconds=10, milliseconds=00)
# generate new id for audio noise removed
new_audio_noise_removed_id = generate_new_id(audio_noise_removed_list.lecture_audio_noise_removed_id)
# nr.noise_removalll(video_name)
noise_removal(audio_name)
LectureAudioNoiseRemoved(
lecture_audio_noise_removed_id=new_audio_noise_removed_id,
lecture_audio_id_id=id,
lecturer_date=current_date,
lecture_audio_name=audio_name,
lecture_audio_length=fake_duration
).save()
return Response({
"response": Response.status_code
})
def post(self, request):
LectureAudioNoiseRemoved(
......@@ -39,47 +76,68 @@ class audioNoiseRemovedList(APIView):
class audioToTextList(APIView):
def get(self, request):
lecture_speech_to_text_id = LectureSpeechToText.objects.all()
serializer = LectureSpeechToTextSerializer(lecture_speech_to_text_id, many=True)
#lecture_speech_to_text_id = LectureSpeechToText.objects.all()
#serializer = LectureSpeechToTextSerializer(lecture_speech_to_text_id, many=True)
audio_to_text_list = LectureSpeechToText.objects.order_by('lecture_speech_to_text_id').last()
# return Response(serializer.data)
video_name = request.query_params.get("video_name")
speech_to_text_name = request.query_params.get("speech_to_text_name")
print('video name: ', video_name)
print('file name: ', speech_to_text_name)
id = int(request.query_params.get("id"))
# id = request.query_params.get("id")
stt.speech_to_text(video_name)
# 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)
speech_to_text(speech_to_text_name)
LectureSpeechToText(
lecture_speech_to_text_id=new_speech_to_text_id,
lecture_audio_id_id=id,
audio_original_text=speech_to_text_name
).save()
return Response({
"response": "successful"
"response": Response.status_code
})
def post(self, request):
# video_name = request.data["video_name"]
#
# print('video name: ', video_name)
#
# stt.speech_to_text(video_name)
LectureSpeechToText(
lecture_speech_to_text_id=request.data["lecture_speech_to_text_id"],
lecture_audio_id=request.data["lecture_audio_id"],
audio_original_text=request.data["audio_original_text"]
audio_original_text=request.data["audio_original_text"],
).save()
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)
# serializer = LectureAudioSummarySerializer(lecture_audio_summary_id, many=True)
# return Response(serializer.data)
def post(self, request):
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"))
# generate new id for summary
lecture_summary_id = "LSUM0001" if lecture_summary_list is None else generate_new_id(lecture_summary_list.lecture_audio_summary_id)
text, summary = LectureSummary(lecture_summary_name)
LectureAudioSummary(
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})
def post(self, request):
LectureAudioSummary(
lecture_speech_to_text_id=request.data["lecture_speech_to_text_id"],
lecture_audio_id=request.data["lecture_audio_id"],
......@@ -90,12 +148,31 @@ class lectureSummaryList(APIView):
class lectureNoticeList(APIView):
class LectureNoticeList(APIView):
def get(self, request):
lecture_notice_id = LectureNotices.objects.all()
serializer = LectureNoticesSerializer(lecture_notice_id, many=True)
return Response(serializer.data)
# serializer = LectureNoticesSerializer(lecture_notice_id, many=True)
# return Response(serializer.data)
lecture_notice_list = LectureNotices.objects.order_by('lecture_notice_id').last()
lecture_notice_name = request.query_params.get("lecture_notice_name")
id = int(request.query_params.get("id"))
# 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)
LectureNotices(
lecture_notice_id=notice_id,
lecture_audio_id=id,
notice_text=text
).save()
return Response({"response": request.data})
def post(self, request):
LectureNotices(
......
import librosa
from pysndfx import AudioEffectsChain
import python_speech_features
import os
def noise_removal(video_name):
def read_file(file_name):
sample_file = file_name
sample_directory = 'lectures/'
sample_path = sample_directory + sample_file
# sample_file = file_name
# sample_directory = 'lectures/'
# sample_path = sample_directory + sample_file
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))
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"))
print('destination directory: ', DESTINATION_DIR)
# generating audio time series and a sampling rate (int)
a, sr = librosa.load(sample_path)
a, sr = librosa.load(path=LECTURE_VIDEO_DIR)
print('a: ', a)
print('sr: ', sr)
# speech_boosted = mffc_highshelf(a, sr)
output_file(destination=DESTINATION_DIR, filename=video_name, a=a, sr=sr)
return a, sr
......@@ -24,6 +39,7 @@ def mffc_highshelf(a, sr):
mfcc = python_speech_features.base.logfbank(a)
mfcc = python_speech_features.base.lifter(mfcc)
sum_of_squares = []
index = -1
for r in mfcc:
......@@ -40,73 +56,25 @@ def mffc_highshelf(a, sr):
speech_booster = AudioEffectsChain().highshelf(frequency=min_hz*(-1)*1.2, gain=-12.0, slope=0.6).limiter(gain=8.0)
a_speach_boosted = speech_booster(a)
# a_speach_boosted = speech_booster.
return (a_speach_boosted)
def mfcc_lowshelf(a, sr):
mfcc = python_speech_features.base.mfcc(a)
mfcc = python_speech_features.base.logfbank(a)
mfcc = python_speech_features.base.lifter(mfcc)
# def trim_silence(y):
# a_trimmed, index = librosa.effects.trim(y, top_db=20, frame_length=2, hop_length=500)
# trimmed_length = librosa.get_duration(y) - librosa.get_duration(a_trimmed)
#
# return a_trimmed, trimmed_length
sum_of_squares = []
index = -1
for x in mfcc:
sum_of_squares.append(0)
index = index + 1
for n in x:
sum_of_squares[index] = sum_of_squares[index] + n**2
strongest_frame = sum_of_squares.index(max(sum_of_squares))
hz = python_speech_features.base.mel2hz(mfcc[strongest_frame])
max_hz = max(hz)
min_hz = min(hz)
speech_booster = AudioEffectsChain().lowshelf(frequency=min_hz*(-1), gain=12.0, slope=0.5)
a_speach_boosted = speech_booster(a)
return (a_speach_boosted)
def trim_silence(y):
a_trimmed, index = librosa.effects.trim(y, top_db=20, frame_length=2, hop_length=500)
trimmed_length = librosa.get_duration(y) - librosa.get_duration(a_trimmed)
return a_trimmed, trimmed_length
def enhance(y):
apply_audio_effects = AudioEffectsChain().lowshelf(gain=10.0, frequency=260, slope=0.1).reverb(reverberance=25, hf_damping=5, room_scale=5, stereo_depth=50, pre_delay=20, wet_gain=0, wet_only=False)#.normalize()
a_enhanced = apply_audio_effects(y)
return a_enhanced
# def enhance(y):
# apply_audio_effects = AudioEffectsChain().lowshelf(gain=10.0, frequency=260, slope=0.1).reverb(reverberance=25, hf_damping=5, room_scale=5, stereo_depth=50, pre_delay=20, wet_gain=0, wet_only=False)#.normalize()
# a_enhanced = apply_audio_effects(y)
#
# return a_enhanced
def output_file(destination ,filename, a, sr, ext=""):
destination = destination + filename[:-4] + ext + '.wav'
librosa.output.write_wav(destination, a, sr)
lectures = ['Lecture01.wav']
for s in lectures:
filename = s
a, sr = read_file(filename)
# a_reduced_centroid_s = reduce_noise_centroid_s(a, sr)
a_reduced_mfcc_lowshelf = mfcc_lowshelf(a, sr)
a_reduced_mfcc_highshelf = mffc_highshelf(a, sr)
# trimming silences
# a_reduced_centroid_s, time_trimmed = trim_silence(a_reduced_centroid_s)
a_reduced_mfcc_up, time_trimmed = trim_silence(mfcc_lowshelf)
a_reduced_mfcc_down, time_trimmed = trim_silence(mffc_highshelf)
# output_file('lectures_trimmed_noise_reduced/' ,filename, y_reduced_centroid_s, sr, '_ctr_s')
output_file('lectures_trimmed_noise_reduced/' ,filename, a_reduced_mfcc_up, sr, '_mfcc_up')
# output_file('lectures_trimmed_noise_reduced/' ,filename, a_reduced_mfcc_down, sr, '_mfcc_down')
# output_file('lectures_trimmed_noise_reduced/' ,filename, a, sr, '_org')
......@@ -4,54 +4,63 @@ from scipy.io.wavfile import read
from scipy.io.wavfile import write
from scipy import signal
import matplotlib.pyplot as mplt
import os
#get_ipython().magic('matplotlib inline')
(Frequency, array) = read('lectures/Lecture01.wav')
len(array)
def noise_removalll(video_name):
mplt.plot(array)
mplt.title('Original Signal Spectrum')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
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))
fourierTransformation = sip.fft(array)
# (Frequency, array) = read('lectures/Lecture01.wav')
# (Frequency, array) = read('lectures/{}'.format(video_name))
(Frequency, array) = read(LECTURE_VIDEO_DIR)
scale = sip.linspace(0, Frequency, len(array))
len(array)
mplt.stem(scale[0:5000], nump.abs(fourierTransformation[0:5000]), 'r')
mplt.title('Signal spectrum after FFT')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
mplt.plot(array)
mplt.title('Original Signal Spectrum')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
fourierTransformation = sip.fft(array)
guassianNoise = nump.random.rand(len(fourierTransformation))
scale = sip.linspace(0, Frequency, len(array))
mplt.stem(scale[0:5000], nump.abs(fourierTransformation[0:5000]), 'r')
mplt.title('Signal spectrum after FFT')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
NewSound = guassianNoise + array
write("New-Sound-Added-With-Guassian-Noise.wav", Frequency, NewSound)
guassianNoise = nump.random.rand(len(fourierTransformation))
u,v = signal.butter(5, 1000/(Frequency/2), btype='highpass')
filteredSignal = signal.lfilter(u,v,NewSound)
NewSound = guassianNoise + array
# plotting the signal.
mplt.plot(filteredSignal)
mplt.title('Highpass Filter')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
write("New-Sound-Added-With-Guassian-Noise.wav", Frequency, NewSound)
# ButterWorth low-filter
x,y = signal.butter(5, 380/(Frequency/2), btype='lowpass')
u,v = signal.butter(5, 1000/(Frequency/2), btype='highpass')
# Applying the filter to the signal
newFilteredSignal = signal.lfilter(x,y,filteredSignal)
filteredSignal = signal.lfilter(u,v,NewSound)
# plotting the signal.
mplt.plot(newFilteredSignal)
mplt.title('Lowpass Filter')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
# plotting the signal.
mplt.plot(filteredSignal)
mplt.title('Highpass Filter')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
write("removed.wav", Frequency, nump.int16(newFilteredSignal/nump.max(nump.abs(newFilteredSignal)) * 32767))
\ No newline at end of file
# ButterWorth low-filter
x,y = signal.butter(5, 380/(Frequency/2), btype='lowpass')
# Applying the filter to the signal
newFilteredSignal = signal.lfilter(x,y,filteredSignal)
# plotting the signal.
mplt.plot(newFilteredSignal)
mplt.title('Lowpass Filter')
mplt.xlabel('Frequency(Hz)')
mplt.ylabel('Amplitude')
write("removed.wav", Frequency, nump.int16(newFilteredSignal/nump.max(nump.abs(newFilteredSignal)) * 32767))
\ No newline at end of file
......@@ -2,17 +2,23 @@ import speech_recognition as sr
import os
def speech_to_text(video_name):
def speech_to_text(speech_to_text_name):
#calling the Recognizer()
r = sr.Recognizer()
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
VIDEO_PATH = os.path.join(BASE_DIR, "lectures\\{}".format(video_name))
# 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))
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(VIDEO_PATH) as source:
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)
......
{% extends 'FirstApp/template.html' %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lecture Recording</title>
</head>
<body>
% block javascript %}
{% load static %}
<!-- Bootstrap core JavaScript-->
<script src="{% static 'FirstApp/vendor/jquery/jquery.min.js' %}"></script>
<script src="{% static 'FirstApp/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<!-- Page level plugins -->
<script src="{% static 'FirstApp/vendor/datatables/jquery.dataTables.min.js' %}"></script>
<script src="{% static 'FirstApp/vendor/datatables/dataTables.bootstrap4.min.js' %}"></script>
<!-- Page level custom scripts -->
<script src="{% static 'FirstApp/js/demo/datatables-demo.js' %}"></script>
<!-- Core plugin JavaScript-->
<script src="{% static 'FirstApp/vendor/jquery-easing/jquery.easing.min.js' %}"></script>
<!-- Load TensorFlow.js -->
<script src="https://unpkg.com/@tensorflow/tfjs"></script>
<!-- Load Posenet -->
<script src="https://unpkg.com/@tensorflow-models/posenet">
</script>
{% endblock %}
<div id="wrapper">
<div id="content-wrapper" class="d-flex flex-column">
<div id="content">
{% block 'container-fluid' %}
<div class="container-fluid">
{% load static %}
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Lecture Record</h1>
</div>
<div>
<button TYPE="button" class="btn btn-success audio_process">Start Recording</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<!--{% extends 'FirstApp/template.html' %}-->
<!--<!DOCTYPE html>-->
<!--<html lang="en">-->
<!--<head>-->
<!-- <meta charset="UTF-8">-->
<!-- <title>Lecture Recording</title>-->
<!--</head>-->
<!--<body>-->
<!--% block javascript %}-->
<!--{% load static %}-->
<!--&lt;!&ndash; Bootstrap core JavaScript&ndash;&gt;-->
<!--<script src="{% static 'FirstApp/vendor/jquery/jquery.min.js' %}"></script>-->
<!--<script src="{% static 'FirstApp/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>-->
<!--&lt;!&ndash; Page level plugins &ndash;&gt;-->
<!--<script src="{% static 'FirstApp/vendor/datatables/jquery.dataTables.min.js' %}"></script>-->
<!--<script src="{% static 'FirstApp/vendor/datatables/dataTables.bootstrap4.min.js' %}"></script>-->
<!--&lt;!&ndash; Page level custom scripts &ndash;&gt;-->
<!--<script src="{% static 'FirstApp/js/demo/datatables-demo.js' %}"></script>-->
<!--&lt;!&ndash; Core plugin JavaScript&ndash;&gt;-->
<!--<script src="{% static 'FirstApp/vendor/jquery-easing/jquery.easing.min.js' %}"></script>-->
<!--&lt;!&ndash; Load TensorFlow.js &ndash;&gt;-->
<!--<script src="https://unpkg.com/@tensorflow/tfjs"></script>-->
<!--&lt;!&ndash; Load Posenet &ndash;&gt;-->
<!--<script src="https://unpkg.com/@tensorflow-models/posenet">-->
<!--</script>-->
<!--{% endblock %}-->
<!--<div id="wrapper">-->
<!-- <div id="content-wrapper" class="d-flex flex-column">-->
<!-- <div id="content">-->
<!-- {% block 'container-fluid' %}-->
<!-- <div class="container-fluid">-->
<!-- {% load static %}-->
<!-- <div class="d-sm-flex align-items-center justify-content-between mb-4">-->
<!-- <h1 class="h3 mb-0 text-gray-800">Lecture Record</h1>-->
<!-- </div>-->
<!-- <div>-->
<!-- <button TYPE="button" class="btn btn-success audio_process">Start Recording</button>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!--</div>-->
<!--</body>-->
<!--</html>-->
\ No newline at end of file
......@@ -34,43 +34,102 @@
$(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";-->
alert('id: ' + id);
alert('speech to text file name: ' + speech_to_text_name);
//call the fetch API
fetch('http://127.0.0.1:8000/summary/lecture-audio-to-text/?video_name=Lecture01.wav')
fetch('http://127.0.0.1:8000/summary/lecture-audio-to-text/?speech_to_text_name=' + speech_to_text_name + '&id=' + id)
.then((res) => res.json())
.then((out) => alert(out.response))
.then((out) => handleSpeechToText(out.response))
.catch((err) => alert('error: ' + err))
});
//this function will handle the success response for speech-to-text
function handleSpeechToText(response) {
if (response === 200) {
document.location.reload();
}
}
<!-- background noise-->
$('.audio_process').click(function() {
$('.audio_process').click(function(e) {
alert('Processing');
let id = e.target.parentNode.parentNode.getAttribute('id');
let audio_name = e.target.parentNode.parentNode.getAttribute('data-audio-name');
audio_name = audio_name + ".wav";
alert('id: ' + id);
alert('audio name: ' + audio_name);
//call the fetch API
fetch('http://127.0.0.1:8000/summary/lecture-audio-to-text/?video_name=Lecture01.wav')
fetch('http://127.0.0.1:8000/summary/lecture-audio-noise-removed/?audio_name=' + audio_name + '&id=' + id)
.then((res) => res.json())
.then((out) => alert(out.response))
.then((out) => handleNoiseRemoved(out.response))
.catch((err) => alert('error: ' + err))
});
//this function will handle the success respopnse for noise removed
function handleNoiseRemoved(response) {
if (response === 200) {
document.location.reload();
}
}
<!-- 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');-->
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);
alert('lecture_summary_name: ' + lecture_summary_name);
//call the fetch API
fetch('http://127.0.0.1:8000/summary/lecture-audio-to-text/?video_name=Lecture01.wav')
//call the fetch API
fetch('http://127.0.0.1:8000/summary/lecture-summary/?lecture_summary_name=' + lecture_summary_name + '&id=' + id)
.then((res) => res.json())
.then((out) => alert(out.response))
.then((out) => handleLectureRemoved(out.response))
.catch((err) => alert('error: ' + err))
});
//this function will handle the success response for summary
function handleLectureRemoved(response) {
if (response === 200) {
document.location.reload();
}
}
<!-- To Notice-->
$('.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');
lecture_notice_name = lecture_notice_name + ".wav.txt";
alert('id: ' + id);
alert('lecture_notice_name: ' + lecture_notice_name);
//call the fetch API
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))
});
//this function will handle the success response for notices
function handleNoticeRemoved(response) {
if (response === 200) {
document.location.reload();
}
}
});
......@@ -108,6 +167,7 @@
<span class="font-italic">No Recordings</span>
</div>
{% else %}
#lecture list
<div class="table-responsive">
<table class="table table-bordered" id="datatable">
<thead>
......@@ -121,7 +181,7 @@
<tbody>
{% for lec_audio in lec_audio_data %}
<tr class="recordings not_clicked" id="{{ lec_audio.lecture_audio_id }}">
<tr class="recordings not_clicked" id="{{ lec_audio.id }}" data-audio-name="{{ lec_audio.lecture_audio_name }}">
<!-- <td>-->
<!-- <div class="radio">-->
<!-- <label><input type="radio"-->
......@@ -168,6 +228,7 @@
<span class="font-italic">No Recordings</span>
</div>
{% else %}
#noise removes list
<div class="table-responsive">
<table class="table table-bordered" id="datatable">
<thead>
......@@ -182,7 +243,7 @@
<tbody>
{% for noiseless_audio in noiseless_data %}
<tr class="recordings not_clicked" id="{{ noiseless_audio.lecture_audio_id }}">
<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"-->
......@@ -250,7 +311,7 @@
<tbody>
{% for lec_text in lecture_text_data %}
<tr class="recordings not_clicked" id="{{ 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}}" >
<!-- <td>-->
<!-- <div class="radio">-->
<!-- <label><input type="radio"-->
......@@ -268,7 +329,7 @@
</button>
</td>
<td>
<button TYPE="button" class="btn btn-danger get_notices">Notices
<button TYPE="button" class="btn btn-success get_notices">Notices
</button>
</td>
</tr>
......
......@@ -8,7 +8,7 @@ router = routers.DefaultRouter()
urlpatterns = [
path('lecture', views.summarization),
path('record', views.lectureRecord),
# path('record', views.lectureRecord),
# API to retrieve lecture summarizing details
......@@ -18,9 +18,9 @@ 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()),
url(r'^lecture-notices/$', api.LectureNoticeList.as_view()),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
......
......@@ -13,7 +13,7 @@ def lectureRecord(request):
print('lecture record data: ', lecture_audio_ser.data)
return render(request, "LectureSummarizationApp/RecordLecture.html")
return render(request, "LectureSummarizingApp/RecordLecture.html")
# Views used in Lecture Summarization
......
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