commit 0b0c063ae1701fa0aeb0749d34a19af7da975d32 Author: nitin2606 Date: Mon Dec 25 10:32:22 2023 +0530 first commit diff --git a/Friendly_new.mp4 b/Friendly_new.mp4 new file mode 100644 index 0000000..c1bbd07 Binary files /dev/null and b/Friendly_new.mp4 differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/__pycache__/question.cpython-38.pyc b/__pycache__/question.cpython-38.pyc new file mode 100644 index 0000000..0ff7eec Binary files /dev/null and b/__pycache__/question.cpython-38.pyc differ diff --git a/app.py b/app.py new file mode 100644 index 0000000..1971755 --- /dev/null +++ b/app.py @@ -0,0 +1,113 @@ +from flask import Flask, render_template, jsonify +from flask_socketio import SocketIO + +import os +import speech_recognition as sr +import question +import imageio +import threading +import time + +app = Flask(__name__) +socketio = SocketIO(app) + +current_directory = os.path.dirname(os.path.realpath(__file__)) + +intents_and_question = question.intents_and_question +video_urls = question.video_urls + +micPermission = True + +class SharedData: + + def __init__(self): + + self.micPermission = micPermission + #self.pause_event = threading.Event() + #self.listening_state = True + + +def get_intent(text): + lowercase_text = text.lower() + matching_intent = [intent for intent, questions in intents_and_question.items() if any(q in lowercase_text for q in questions)] + return matching_intent[0] if matching_intent else 'no_answer' + + +def get_video_response(intent): + return video_urls.get(intent) + + +def calc_video_length(url): + try: + reader = imageio.get_reader(url) + duration = reader.get_meta_data()['duration'] + reader.close() + return duration + except Exception as e: + return "error" + + +def recognize_and_emit(shared_data): + + recognizer = sr.Recognizer() + + if shared_data.micPermission is True: + with sr.Microphone() as source: + while True: + try: + + #shared_data.pause_event.wait() + print("Listening ....") + audio_data = recognizer.record(source, duration = 3.5) + #audio_data = recognizer.listen(source, timeout=3) + print("Recognizing your text .........") + text = recognizer.recognize_google(audio_data) + + + intent = get_intent(text.strip()) + video_url = get_video_response(intent) + + length = calc_video_length(video_url) + + #shared_data.length = length + + + + socketio.emit('text_received', {'text': text, 'intent': intent, 'video_url': video_url}) + print("Recognized Text:", text) + + shared_data.micPermission = False + print("Going to sleep...") + source = None + time.sleep(length) + shared_data.micPermission = True + recognize_and_emit(shared_data) + + + + except sr.UnknownValueError: + print("Speech Recognition could not understand audio") + except sr.RequestError as e: + print(f"Could not request {e}") + + + +@app.route('/') +def index(): + return render_template('index.html') + + +@socketio.on('start_listening') +def start_listening(data): + + shared_data = SharedData() + recognition_thread = threading.Thread(target=recognize_and_emit, args=(shared_data,)) + recognition_thread.start() + + + #recognition_thread.join() # Wait for the recognition thread to finish + + + +if __name__ == '__main__': + socketio.run(app, debug=True) \ No newline at end of file diff --git a/question.py b/question.py new file mode 100644 index 0000000..6b4f12d --- /dev/null +++ b/question.py @@ -0,0 +1,209 @@ +import os + + +current_directory = os.path.dirname(os.path.realpath(__file__)) + +intents_and_question = { + + "greet": [ + + "hey", + "hello", + "Hello?", + "hello?", + "hi", + "hello there", + "good morning", + "good evening", + "moin", + "hey there", + "let's go", + "hey dude", + "goodmorning", + "goodevening", + "good afternoon" + ], + + + + "appointment_booking": [ + + "How can I schedule an appointment", + "I need to book an appointment with a doctor", + "what's the procedure for booking an appointment", + "hello, I'd like to schedule an appointment.", + "book an appointment", + "appointment", + "need an appointment" + ], + + + "doctor_information": [ + + "tell me more about dr. abc", + "what's the specialty of dr. abc", + "give me the contact details for dr. abc" + "doctor", + "contact doctor", + "doctor contact", + "doctor detail", + "detail doctor" + + ], + + + "department_information": [ + + "which departments are available in the hospital", + "can you provide details about the cardiology department", + "tell me more about the pediatric department", + "department", + "which department", + "department info" + + ], + + + "visiting_hours":[ + + "what are the visiting hours for patients", + "when can I visit a patient in the hospital", + "is there a specific time for visiting hours", + "visiting time", + "visit", + "time", + "time to visit", + "visit time", + "hospital visit", + "visit hospital" + ], + + + "location_and_directions":[ + + "how do I get to the hospital", + "can you provide me with directions to your location", + "where is the hospital situated", + "direction", + "direction hospital", + "hospital direction", + "location", + "hospital location" + ], + + + "billing_and_insurance": [ + + "how do I pay my medical bills", + "do you accept my insurance", + "what's the billing process for a hospital stay", + "bills", + "insurance", + "pay bill", + ], + + + "medical_records": [ + "how can I access my medical records", + "request my medical history", + "I need a copy of my lab results", + "medical records", + "medical record", + "record", + "records", + "record medical", + "results", + "lab results", + "result copy", + "copy result" + ], + + + "emergency_services": [ + "what should I do in case of a medical emergency", + "how do I contact the hospital in an emergency", + "tell me about your emergency services", + "emergency", + "emergency service" + ], + + + "covid19_information": [ + "what safety measures are in place due to COVID-19", + "is it safe to visit the hospital during the pandemic", + "do you offer COVID-19 testing or vaccinations", + "covid19" + + ], + + + "feedback_and_complaints": [ + "I want to provide feedback about my experience", + "how can I file a complaint about a staff member", + "share my thoughts on my recent visit", + "feedback", + "complaints", + "complain", + "share thoughts", + "experiance" + ], + + + "general_information": [ + "tell me more about the hospital", + "what services do you offer", + "is there a cafeteria in the hospital", + "information", + "cafeteria", + "services", + "services offered", + "offered services" + ], + + "diabetes_information": [ + + "diabetes", + "what precautions are to be taken in case of diabetes", + "precautions", + "case of diabetes", + "precautions taken" + + ], + + +} + + +video_urls = { + + "greet": "static/greet.mp4", + "appointment_booking": "static/appointment_booking.mp4", + "doctor_information": "static/doctor_information.mp4", + "department_information": "static/department_information.mp4", + "visiting_hours": "static/visiting_hours.mp4", + "location_and_directions": "static/location_and_directions.mp4", + "billing_and_insurance": "static/billing_and_insurance.mp4", + "medical_records": "static/medical_records.mp4", + "emergency_services": "static/emergency_services.mp4", + "covid19_information": "static/covid19_information.mp4", + "feedback_and_complaints": "static/feedback_and_complaints.mp4", + "thank_you": "static/thank_you.mp4", + "general_information": "static/general_information.mp4", + "diabetes_information": "static/diabetes_information.mp4", + "no_answer": "static/no_answer.mp4", + + + } + + +def get_video_response(intent): + + return video_urls.get(intent) + + + +#print(get_video_response('greet')) + + + + diff --git a/static/Friendly_new.mp4 b/static/Friendly_new.mp4 new file mode 100644 index 0000000..c1bbd07 Binary files /dev/null and b/static/Friendly_new.mp4 differ diff --git a/static/appointment_booking.mp4 b/static/appointment_booking.mp4 new file mode 100644 index 0000000..03fa490 Binary files /dev/null and b/static/appointment_booking.mp4 differ diff --git a/static/billing_and_insurance.mp4 b/static/billing_and_insurance.mp4 new file mode 100644 index 0000000..0e8e06b Binary files /dev/null and b/static/billing_and_insurance.mp4 differ diff --git a/static/covid19_information.mp4 b/static/covid19_information.mp4 new file mode 100644 index 0000000..5b0a499 Binary files /dev/null and b/static/covid19_information.mp4 differ diff --git a/static/department_information.mp4 b/static/department_information.mp4 new file mode 100644 index 0000000..8ff9297 Binary files /dev/null and b/static/department_information.mp4 differ diff --git a/static/diabetes_information.mp4 b/static/diabetes_information.mp4 new file mode 100644 index 0000000..60f20ce Binary files /dev/null and b/static/diabetes_information.mp4 differ diff --git a/static/doctor_information.mp4 b/static/doctor_information.mp4 new file mode 100644 index 0000000..f478a70 Binary files /dev/null and b/static/doctor_information.mp4 differ diff --git a/static/emergency_services.mp4 b/static/emergency_services.mp4 new file mode 100644 index 0000000..032f0ad Binary files /dev/null and b/static/emergency_services.mp4 differ diff --git a/static/feedback_and_complaints.mp4 b/static/feedback_and_complaints.mp4 new file mode 100644 index 0000000..d3a6b9c Binary files /dev/null and b/static/feedback_and_complaints.mp4 differ diff --git a/static/general_information.mp4 b/static/general_information.mp4 new file mode 100644 index 0000000..3e238b6 Binary files /dev/null and b/static/general_information.mp4 differ diff --git a/static/greet.mp4 b/static/greet.mp4 new file mode 100644 index 0000000..e9456e5 Binary files /dev/null and b/static/greet.mp4 differ diff --git a/static/location_and_directions.mp4 b/static/location_and_directions.mp4 new file mode 100644 index 0000000..b7f3980 Binary files /dev/null and b/static/location_and_directions.mp4 differ diff --git a/static/medical_records.mp4 b/static/medical_records.mp4 new file mode 100644 index 0000000..5554e2a Binary files /dev/null and b/static/medical_records.mp4 differ diff --git a/static/no_answer.mp4 b/static/no_answer.mp4 new file mode 100644 index 0000000..8fbf6d7 Binary files /dev/null and b/static/no_answer.mp4 differ diff --git a/static/thank_you.mp4 b/static/thank_you.mp4 new file mode 100644 index 0000000..73814cc Binary files /dev/null and b/static/thank_you.mp4 differ diff --git a/static/visiting_hours.mp4 b/static/visiting_hours.mp4 new file mode 100644 index 0000000..2bcdea0 Binary files /dev/null and b/static/visiting_hours.mp4 differ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..0ede947 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,95 @@ + + + + + + CONVO + + + + + + + + + +

CONVO

+ + + + + diff --git a/video/appointment_booking.mp4 b/video/appointment_booking.mp4 new file mode 100644 index 0000000..03fa490 Binary files /dev/null and b/video/appointment_booking.mp4 differ diff --git a/video/billing_and_insurance.mp4 b/video/billing_and_insurance.mp4 new file mode 100644 index 0000000..0e8e06b Binary files /dev/null and b/video/billing_and_insurance.mp4 differ diff --git a/video/covid19_information.mp4 b/video/covid19_information.mp4 new file mode 100644 index 0000000..5b0a499 Binary files /dev/null and b/video/covid19_information.mp4 differ diff --git a/video/department_information.mp4 b/video/department_information.mp4 new file mode 100644 index 0000000..8ff9297 Binary files /dev/null and b/video/department_information.mp4 differ diff --git a/video/diabetes_information.mp4 b/video/diabetes_information.mp4 new file mode 100644 index 0000000..60f20ce Binary files /dev/null and b/video/diabetes_information.mp4 differ diff --git a/video/doctor_information.mp4 b/video/doctor_information.mp4 new file mode 100644 index 0000000..f478a70 Binary files /dev/null and b/video/doctor_information.mp4 differ diff --git a/video/emergency_services.mp4 b/video/emergency_services.mp4 new file mode 100644 index 0000000..032f0ad Binary files /dev/null and b/video/emergency_services.mp4 differ diff --git a/video/feedback_and_complaints.mp4 b/video/feedback_and_complaints.mp4 new file mode 100644 index 0000000..d3a6b9c Binary files /dev/null and b/video/feedback_and_complaints.mp4 differ diff --git a/video/general_information.mp4 b/video/general_information.mp4 new file mode 100644 index 0000000..3e238b6 Binary files /dev/null and b/video/general_information.mp4 differ diff --git a/video/greet.mp4 b/video/greet.mp4 new file mode 100644 index 0000000..e9456e5 Binary files /dev/null and b/video/greet.mp4 differ diff --git a/video/location_and_directions.mp4 b/video/location_and_directions.mp4 new file mode 100644 index 0000000..b7f3980 Binary files /dev/null and b/video/location_and_directions.mp4 differ diff --git a/video/medical_records.mp4 b/video/medical_records.mp4 new file mode 100644 index 0000000..5554e2a Binary files /dev/null and b/video/medical_records.mp4 differ diff --git a/video/no_answer.mp4 b/video/no_answer.mp4 new file mode 100644 index 0000000..8fbf6d7 Binary files /dev/null and b/video/no_answer.mp4 differ diff --git a/video/thank_you.mp4 b/video/thank_you.mp4 new file mode 100644 index 0000000..73814cc Binary files /dev/null and b/video/thank_you.mp4 differ diff --git a/video/visiting_hours.mp4 b/video/visiting_hours.mp4 new file mode 100644 index 0000000..2bcdea0 Binary files /dev/null and b/video/visiting_hours.mp4 differ