From a5837a4b28e49f19c0e8bec1cda40176b9e6c0b1 Mon Sep 17 00:00:00 2001 From: Ryan-Horng Date: Thu, 23 Nov 2023 21:50:14 -0500 Subject: [PATCH] Set up the basic machine learning py --- .../machine_learning_client.py | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/machine-learning-client/machine_learning_client.py b/machine-learning-client/machine_learning_client.py index a6ecbb1..0335db0 100644 --- a/machine-learning-client/machine_learning_client.py +++ b/machine-learning-client/machine_learning_client.py @@ -1,19 +1,35 @@ -from flask import Flask, render_template, request, redirect, url_for, make_response, session import os from pymongo import MongoClient import pymongo import datetime -from bson.objectid import ObjectId +import speech_recognition as sr import sys -app = Flask('project4') +r = sr.recognizer() -@app.route("/process_wav", methods=['GET', 'POST']) -def process_wav(): - if request.method == 'POST': - audio_file = request.form.get("audio-recording") - dir = 'audio/'+str(audio_file) +def record_microphone(): + with sr.Microphone() as source: + print("Please give your answer:") + audio = r.listen(source) + return audio + +def audio_to_text(audio): + try: + transcription = r.recognize_google(audio) + print(transcription) + except sr.UnknownValueError: + print("Sorry, we could not recognize your response.") + except sr.RequestError as e: + print("Sorry, there appears to be an error with Google Speech to Text") + +def grade_response(transcription): + print("working on it...") + +def main(): + print("Tell me a little bit about yourself") + audio = record_microphone() + transcription = audio_to_text(audio) + result = grade_response(transcription) if __name__ == "__main__": - PORT = os.getenv('PORT', 5000) - app.run(debug=True,port=PORT) + main() \ No newline at end of file