Skip to content

Commit

Permalink
black and linted
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-Horng committed Nov 27, 2023
1 parent 8f5e874 commit 203dc21
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
42 changes: 29 additions & 13 deletions machine-learning-client/machine_learning_client.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,60 @@
"""
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()
print("Mic init successful")
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):
"""
Expand All @@ -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()
main()
36 changes: 25 additions & 11 deletions web-app/app.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions web-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
pymongo

0 comments on commit 203dc21

Please sign in to comment.