Skip to content

Commit

Permalink
editing yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
KeiOshima committed Nov 30, 2023
1 parent 71b9090 commit b38b69d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 86 deletions.
75 changes: 4 additions & 71 deletions machine-learning-client/machine_learning_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from enum import Enum
import pyaudio
import speech_recognition as sr
<<<<<<< HEAD


class ML:
"""Machine Learning class functions """
"""Machine Learning class functions"""

pa = pyaudio.PyAudio()

def list_all_mic(self):
Expand Down Expand Up @@ -56,66 +57,7 @@ def audio_to_text(self, audio_file_string):

class BuzzWord(Enum):
"""List of Buzzwords"""
HELLO = "hello"
UGH = "ugh"

def grade_response(self, transcription):
"""
Give out a score based on the transcribed audio

=======
class ML:
"""Machine Learning class functions """
pa = pyaudio.PyAudio()
def list_all_mic(self):
"""
List all available microphone device
"""
if len(sr.Microphone.list_microphone_names()) == 0:
print("no device available")
return
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print(f'Microphone with name "{name}"')
print(f" found for `Microphone(device_index={index})`")
def record_microphone(self):
"""Function for recording microphone input"""
ML.list_all_mic(self) # 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:")
r = sr.Recognizer()
audio = r.listen(source)
return audio
def audio_to_text(self, audio_file_string):
"""Function for converting audio file to text transcription"""
r = sr.Recognizer()
with sr.AudioFile(audio_file_string) as source:
ad = r.listen(source)
try:
transcription = r.recognize_google(ad)
print(transcription)
print(type(transcription))
except sr.UnknownValueError:
print("Sorry, we could not recognize your response.")
except sr.RequestError:
print("Sorry, there appears to be an error with Google Speech to Text")
return transcription
class BuzzWord(Enum):
"""List of Buzzwords"""
HELLO = "hello"
UGH = "ugh"

Expand All @@ -124,7 +66,6 @@ def grade_response(self, transcription):
Give out a score based on the transcribed audio
>>>>>>> 5a0af371e4dbfe2fdc0328cf9e5f1e13a84def20
Args:
transcription (str): transcribed audio
"""
Expand All @@ -140,19 +81,11 @@ def main():
"""Main Method"""
print("Tell me a little bit about yourself")
ml = ML()
<<<<<<< HEAD
audio = r'..\\web-app\uploads\user_audio.wav'
audio = r"..\\web-app\uploads\user_audio.wav"
transcription = ml.audio_to_text(audio)
result = ml.grade_response(transcription)
print(result)
print("test main")

=======
audio = ml.record_microphone()
transcription = ml.audio_to_text(audio)
result = ml.grade_response(transcription)
print(result)
>>>>>>> 5a0af371e4dbfe2fdc0328cf9e5f1e13a84def20


if __name__ == "__main__":
Expand Down
37 changes: 22 additions & 15 deletions web-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,37 @@
import os
import subprocess

app = Flask('project4')
app = Flask("project4")

app.config['UPLOAD_FOLDER'] = 'uploads'
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
app.config["UPLOAD_FOLDER"] = "uploads"
os.makedirs(app.config["UPLOAD_FOLDER"], exist_ok=True)

@app.route('/')

@app.route("/")
def RootPage():
return render_template('root.html')
return render_template("root.html")


@app.route('/analyzeData', methods=['POST'])
@app.route("/analyzeData", methods=["POST"])
def analyzeData():
try:
if 'audio' not in request.files:
if "audio" not in request.files:
return jsonify({"status": "error", "message": "No audio file provided"})

audio_file = request.files['audio']
audio_path = os.path.join(app.config['UPLOAD_FOLDER'], 'user_audio.wav')
audio_file = request.files["audio"]
audio_path = os.path.join(app.config["UPLOAD_FOLDER"], "user_audio.wav")
audio_file.save(audio_path)


print("Audio file saved at:", audio_path)
result = subprocess.run(["C:\\Users\\Andrew - User\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe", "E:\\4-containerized-app-exercise-rizzballs\\machine-learning-client\\machine_learning_client.py", audio_path], capture_output=True, text=True)

print("Audio file saved at:", audio_path)
result = subprocess.run(
[
"C:\\Users\\Andrew - User\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe",
"E:\\4-containerized-app-exercise-rizzballs\\machine-learning-client\\machine_learning_client.py",
audio_path,
],
capture_output=True,
text=True,
)

return jsonify({"status": "success"})

Expand All @@ -33,6 +41,5 @@ def analyzeData():


if __name__ == "__main__":
PORT = os.getenv('PORT', 5000)
PORT = os.getenv("PORT", 5000)
app.run(debug=True, port=PORT)

0 comments on commit b38b69d

Please sign in to comment.