Skip to content

Commit

Permalink
Merge pull request #44 from ucsd-cse110-fa23/voice-recognition
Browse files Browse the repository at this point in the history
feat: voice recognition
  • Loading branch information
AllKeng authored Nov 6, 2023
2 parents 9f29d4a + cdaf712 commit 9b985a7
Show file tree
Hide file tree
Showing 68 changed files with 1,076 additions and 485 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

46 changes: 46 additions & 0 deletions .github/workflows/run-unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Java CI

on: [push]

permissions:
contents: read
checks: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Install Xvfb
run: |
sudo apt-get update
sudo apt-get install -y xvfb
continue-on-error: true

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

# build everything (includes running unit tests)
- name: Execute Gradle build
run: xvfb-run -a ./gradlew build

# report the results
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
detailed_summary: true # display detailed summary of the report
include_passed: true # include passed tests in the results table
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Created by https://www.toptal.com/developers/gitignore/api/java
# Edit at https://www.toptal.com/developers/gitignore?templates=java

# VSCode
.vscode

### Java ###
# Compiled class file
*.class
Expand Down Expand Up @@ -29,4 +32,7 @@ replay_pid*

# End of https://www.toptal.com/developers/gitignore/api/java
*.wav
*.properties
*.properties
!.vscode/launch.json
!gradle/wrapper/gradle-wrapper.jar
!gradle/wrapper/gradle-wrapper.properties
Binary file added .gradle/7.4.2/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/7.4.2/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/7.4.2/checksums/sha1-checksums.bin
Binary file not shown.
Binary file not shown.
Binary file added .gradle/7.4.2/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/7.4.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/8.0.2/checksums/checksums.lock
Binary file not shown.
Binary file added .gradle/8.0.2/checksums/md5-checksums.bin
Binary file not shown.
Binary file added .gradle/8.0.2/checksums/sha1-checksums.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .gradle/8.0.2/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/8.0.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added .gradle/8.0.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/8.0.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file added .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file added .gradle/file-system.probe
Binary file not shown.
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@
"name": "App",
"request": "launch",
"mainClass": "View.java",
"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
//"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
},
{
"type": "java",
"name": "AudioRecorder",
"request": "launch",
"mainClass": "multithreading.AudioRecorder",
"projectName": "cse110-lab5_d0dfa5ee",
"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
//"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
},
{
"type": "java",
"name": "ThreadingNoThread",
"request": "launch",
"mainClass": "multithreading.ThreadingNoThread",
"projectName": "cse110-lab5_d0dfa5ee",
"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
//"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
},
{
"type": "java",
"name": "ThreadingWithThread",
"request": "launch",
"mainClass": "multithreading.ThreadingWithThread",
"projectName": "cse110-lab5_d0dfa5ee",
"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
//"vmArgs": "--module-path 'C:\\Users\\Christophian S\\Desktop\\javafx-sdk-21\\lib' --add-modules javafx.controls,javafx.fxml"
},
{
"type": "java",
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"java.debug.settings.onBuildFailureProceed": true
"java.compile.nullAnalysis.mode": "automatic",
"java.project.referencedLibraries": [
"lib/**/*.jar"
],
"java.configuration.updateBuildConfiguration": "interactive"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Lab5-Test
CSE110FA23 Lab 5 - Creating your own HTTP Server and Multithreading
# CSE 110 Project Team 39 Culinary Companion Crew
PantryPals - the application that provides you with recipes that YOU have currently in your possession!
43 changes: 43 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/8.0.2/userguide/building_java_projects.html
*/

plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'

// This dependency is used by the application.
implementation 'com.google.guava:guava:31.1-jre'

implementation 'org.json:json:20180813'
}

application {
// Define the main class for the application.
mainClass = 'src.App'
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}

javafx {
version = "21"
modules = [ 'javafx.controls' ]
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// layout
import javafx.animation.PauseTransition;
import javafx.application.Application;
Expand Down
14 changes: 7 additions & 7 deletions src/client/App.java → app/src/main/java/code/App.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package client;
package code;

import client.Controllers.Controller;
import client.Model.Model;
import client.View.View;
import code.client.Controllers.Controller;
import code.client.Model.Model;
import code.client.View.View;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
Expand All @@ -15,14 +15,14 @@ public static void main(String[] args) {

@Override
public void start(Stage primaryStage) {

View view = new View();
Model model = new Model();
Controller controller = new Controller(view, model);

Scene scene = new Scene(view.getGrid(), 400, 200);
Scene scene = new Scene(view.getGrid(), 1200, 600);
primaryStage.setScene(scene);
primaryStage.setTitle("MyServerUI");
primaryStage.setTitle("PantryPal");
primaryStage.show();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,18 @@
package multithreading;
package code.client.Controllers;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.geometry.Insets;
import java.io.*;
import javax.sound.sampled.*;

class AppFrame extends FlowPane {
private Button startButton;
private Button stopButton;
public class AudioRecorder {
private AudioFormat audioFormat;
private TargetDataLine targetDataLine;
private Label recordingLabel;
private boolean recordingState;

// Set a default style for buttons and fields - background color, font size,
// italics
String defaultButtonStyle = "-fx-border-color: #000000; -fx-font: 13 arial; -fx-pref-width: 175px; -fx-pref-height: 50px;";
String defaultLabelStyle = "-fx-font: 13 arial; -fx-pref-width: 175px; -fx-pref-height: 50px; -fx-text-fill: red; visibility: hidden";

AppFrame() {
// Set properties for the flowpane
this.setPrefSize(370, 120);
this.setPadding(new Insets(5, 0, 5, 5));
this.setVgap(10);
this.setHgap(10);
this.setPrefWrapLength(170);

// Add the buttons and text fields
startButton = new Button("Start");
startButton.setStyle(defaultButtonStyle);

stopButton = new Button("Stop");
stopButton.setStyle(defaultButtonStyle);

recordingLabel = new Label("Recording...");
recordingLabel.setStyle(defaultLabelStyle);

this.getChildren().addAll(startButton, stopButton, recordingLabel);

// Get the audio format
audioFormat = getAudioFormat();

// Add the listeners to the buttons
addListeners();
}

public void addListeners() {
// Start Button
startButton.setOnAction(e -> {
startRecording();
});

// Stop Button
stopButton.setOnAction(e -> {
stopRecording();
});
public AudioRecorder(Label recordingLabel) {
this.audioFormat = getAudioFormat();
this.recordingLabel = recordingLabel;
}

private AudioFormat getAudioFormat() {
Expand Down Expand Up @@ -86,7 +40,7 @@ private AudioFormat getAudioFormat() {
bigEndian);
}

private void startRecording() {
public void startRecording() {
Thread t = new Thread(
new Runnable() {
@Override
Expand Down Expand Up @@ -121,31 +75,19 @@ public void run() {
t.start();
}

private void stopRecording() {
public void stopRecording() {
targetDataLine.stop();
targetDataLine.close();
}
}

public class AudioRecorder extends Application {

@Override
public void start(Stage primaryStage) throws Exception {

// Setting the Layout of the Window (Flow Pane)
AppFrame root = new AppFrame();

// Set the title of the app
primaryStage.setTitle("Audio Recorder");
// Create scene of mentioned size with the border pane
primaryStage.setScene(new Scene(root, 370, 120));
// Make window non-resizable
primaryStage.setResizable(false);
// Show the app
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
public boolean toggleRecording() {
if(recordingState) {
stopRecording();
recordingState = false;
return false;
}
startRecording();
recordingState = true;
return true;
}
}
61 changes: 61 additions & 0 deletions app/src/main/java/code/client/Controllers/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package code.client.Controllers;

import code.client.Controllers.AudioRecorder;
import code.client.Model.Model;
import code.client.View.View;
import javafx.event.ActionEvent;

/*
* Modify t
*/
public class Controller {
private View view;
private Model model;
private AudioRecorder audioRecorder;

public Controller(View view, Model model) {
this.view = view;
this.model = model;
this.audioRecorder = new AudioRecorder(view.getRecordingLabel());

// recording buttons
this.view.setStartButtonAction(this::handleStartButton);
this.view.setStopButtonAction(this::handleStopButton);
}

private void handleStartButton(ActionEvent event) {
audioRecorder.startRecording();
}

private void handleStopButton(ActionEvent event) {
// Makes calls to View
audioRecorder.stopRecording();
}
/*
* private void handlePostButton(ActionEvent event) {
* String language = view.getLanguage();
* String year = view.getYear();
* String response = model.performRequest("POST", language, year, null);
* view.showAlert("Response", response);
* }
*
* private void handleGetButton(ActionEvent event) {
* String query = view.getQuery();
* String response = model.performRequest("GET", null, null, query);
* view.showAlert("Response", response);
* }
*
* private void handlePutButton(ActionEvent event) {
* String language = view.getLanguage();
* String year = view.getYear();
* String response = model.performRequest("PUT", language, year, null);
* view.showAlert("Response", response);
* }
*
* private void handleDeleteButton(ActionEvent event) {
* String query = view.getQuery();
* String response = model.performRequest("DELETE", null, null, query);
* view.showAlert("Response", response);
* }
*/
}
Loading

0 comments on commit 9b985a7

Please sign in to comment.