diff --git a/machine-learning-client/machine_learning_client.py b/machine-learning-client/machine_learning_client.py index ffecd46..e00bebf 100644 --- a/machine-learning-client/machine_learning_client.py +++ b/machine-learning-client/machine_learning_client.py @@ -1,26 +1,35 @@ +""" +Machine Learning python file providing conversion of audio +to text transcription and analysis of audio transcription +""" import os -from pymongo import MongoClient -import pymongo import datetime +import sys +import pymongo +from pymongo import MongoClient import pyaudio import speech_recognition as sr -import sys r = sr.Recognizer() pa = pyaudio.PyAudio() -def listAllMic(): + + +def list_all_mic(): """ List all available microphone device """ - if (len(sr.Microphone.list_microphone_names()) == 0): + if len(sr.Microphone.list_microphone_names()) == 0: print("no device available") return - + for index, name in enumerate(sr.Microphone.list_microphone_names()): - print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name)) + print(f'Microphone with name "{name}"') + print(f" found for `Microphone(device_index={index})`") + def record_microphone(): - listAllMic() #Use for debug + """Function for recording microphone input""" + list_all_mic() # Use for debug mc = None try: mc = sr.Microphone() @@ -28,22 +37,24 @@ def record_microphone(): except OSError: mc = sr.Microphone(0) print("no default mic") - - with mc as source: print("Please give your answer:") audio = r.listen(source) return audio + def audio_to_text(audio): + """Function for converting audio file to text transcription""" try: transcription = r.recognize_google(audio) print(transcription) print(type(transcription)) except sr.UnknownValueError: print("Sorry, we could not recognize your response.") - except sr.RequestError as e: + except sr.RequestError: print("Sorry, there appears to be an error with Google Speech to Text") + return transcription + def grade_response(transcription): """ @@ -54,13 +65,18 @@ def grade_response(transcription): transcription (str): transcribed audio """ print("working on it...") - + grade = transcription + return grade + def main(): + """Main Method""" print("Tell me a little bit about yourself") audio = record_microphone() transcription = audio_to_text(audio) result = grade_response(transcription) + print(result) + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/web-app/app.py b/web-app/app.py index 639092c..42399f8 100644 --- a/web-app/app.py +++ b/web-app/app.py @@ -1,21 +1,35 @@ -from flask import Flask, render_template, request, redirect, url_for, make_response, session +"""Module designed to supplement front end webpage""" import os +import datetime +import sys +from flask import ( + Flask, + render_template, + request, + redirect, + url_for, + make_response, + session, +) from pymongo import MongoClient import pymongo -import datetime from bson.objectid import ObjectId -import sys -app = Flask('project4') +app = Flask("project4") -@app.route('/') -def RootPage(): - return render_template('root.html') -@app.route('/anaylzeData', methods=['POST']) -def anaylzeData(): +@app.route("/") +def root_page(): + """Root page route""" + return render_template("root.html") + + +@app.route("/analyze_data", methods=["POST"]) +def anaylze_data(): + """Analyze data by sending it to the ml client""" return + if __name__ == "__main__": - PORT = os.getenv('PORT', 5000) - app.run(debug=True,port=PORT) + PORT = os.getenv("PORT", 5000) + app.run(debug=True, port=PORT) diff --git a/web-app/requirements.txt b/web-app/requirements.txt new file mode 100644 index 0000000..f028fa2 --- /dev/null +++ b/web-app/requirements.txt @@ -0,0 +1,2 @@ +flask +pymongo \ No newline at end of file