Commit 9899d3f4 authored by NaweenTharuka's avatar NaweenTharuka

feat: Backend for grammer checker

parent 71d82501
from happytransformer import HappyTextClassification,TTSettings, HappyTextToText
import speech_recognition as sr
import moviepy.editor as mp
def grammerchecker():
def convertText():
clip = mp.VideoFileClip(r"F:\\CDAP-PRESENTLY\\21_22-j-02\\Presently\\presently\\media\\video\\22\\publicspeech.mp4")
clip.audio.write_audiofile(r"converted_mp3.wav")
r = sr.Recognizer()
audio =sr.AudioFile(r"converted_mp3.wav")
with audio as source:
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio_file = r.record(source)
stt = r.recognize_google(audio_file)
return stt
def grammerchecker(speechText):
happy_tt = HappyTextClassification(load_path = "F:\\CDAP-PRESENTLY\\21_22-j-02\\Presently\\presently\\users\\models\\grammermodels\\")
beam_settings = TTSettings(num_beams=5, min_length=1, max_length=500)
happy_tt = HappyTextToText("T5", "t5-base")
example_1 = "Sri Lanka's documented history goes back 3,000 years, with evidence of prehistoric human settlements that dates to at least 125,000 years ago.[14] It has a rich cultural heritage. The earliest known Buddhist writings of Sri Lanka, known collectively as the Pāli canon, date to the fourth Buddhist council, which took place in 29 BCE.[15][16] Sri Lanka's geographic location and deep harbours have made it of great strategic importance, from the earliest days of the ancient Silk Road trade route to today's so-called maritime Silk Road"
example_1 = speechText
result_1 = happy_tt.generate_text(example_1, args=beam_settings)
print(result_1.text)
return(result_1.text)
result = grammerchecker()
speechText = convertText()
result = grammerchecker(speechText)
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