Skip to content

Commit

Permalink
Set up the basic machine learning py
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-Horng committed Nov 24, 2023
1 parent c44941f commit a5837a4
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions machine-learning-client/machine_learning_client.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a5837a4

Please sign in to comment.