Commit 24d478af authored by Ranasinghe R.A.P.T's avatar Ranasinghe R.A.P.T

Merge branch 'feature/extract-speech' into 'dev'

Feature/extract speech

See merge request !1
parents 99e14736 8212e2c2
#import flask module
from flask import Flask
from flask_restful import Api
from flask import Flask
from resources.routes import initialize_routes
app = Flask(__name__)
api = Api(app)
#Test route
@app.route('/')
def hello_world():
return 'Hello World'
#initialize all the routes
initialize_routes(api)
#Main function
if __name__ == '__main__':
app.run()
\ No newline at end of file
from .speechExtraction import SpeechExtraction
def initialize_routes(api):
api.add_resource(SpeechExtraction, "/api/extraction")
\ No newline at end of file
from flask_restful import Resource
from loguru import logger
import speech_recognition as sr
import moviepy.editor as mp
import json
class SpeechExtraction(Resource):
# This function uses for extract the speech from a video
# params: self
# return: json
# author: Pamal Ranasinghe
def get(self):
try:
# Check the endpoint execution
logger.info("Speech Extraction - GET - hits")
clip = mp.VideoFileClip(r"assets/sample_video.mov")
clip.audio.write_audiofile(r"assets/converted_wav/converted.wav")
r = sr.Recognizer()
audio = sr.AudioFile("assets/converted_wav/converted.wav")
with audio as source:
audio_file = r.record(source)
result = r.recognize_google(audio_file)
# Create a dict object which includes the result
value = {"text" : result}
#return the json object which is having converted speech
return json.loads(json.dumps(value)), 200
except Exception as e:
logger.error(str(e))
return json.loads(json.dumps({"message" : "Something went wrong"})) , 500
\ No newline at end of file
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