Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .project

This file was deleted.

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Group Members

- Rene Urias Jr.

# Assignment Submission - Augmentive and Alternative Communication Devices

This repository implements an Augmentative and Alternative Communication (AAC) system, allowing users to associate images with corresponding text to facilitate communication. It includes classes for managing categories, images, and their mappings.


## Resources Used

- **Official Java Documentation**: I extensively consulted the [Java documentation](https://docs.oracle.com/javase/8/docs/) to gain clarity on the usage of specific Java methods and classes. This was particularly helpful in understanding how to work with strings, characters, and arrays in Java.
- **StackOverflow**: In instances where I encountered challenges during coding, such as determining the length of user input or implementing certain mathematical aspects related to AAC devices, I sought solutions on [StackOverflow](https://stackoverflow.com/). This platform provided valuable examples and insights.
- **Java Style Guide**: To maintain consistent formatting and adhere to naming conventions, I followed the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). This practice contributes to improved code readability and maintainability.
- **Markdown Guide**: The structure and content of this README.md file were crafted using an [online Markdown guide](https://www.markdownguide.org/). This resource offered guidance on Markdown syntax, enabling effective documentation for the Augmentive and Alternative Communication Devices project.
146 changes: 68 additions & 78 deletions src/AAC.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.JButton;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.Locale;
import java.util.Scanner;

import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import structures.AACMappings;
import structures.KeyNotFoundException;

/**
* Creates a GUI that has a grid of images that represent the
* communication device of the AAC.
* Creates a GUI that has a grid of images that represent the communication device of the AAC.
*
* @author Catie Baker
*
*/
public class AAC implements ActionListener {

private JFrame frame;
//private JButton[][] grid;
private JFrame frame;
// private JButton[][] grid;
private static Synthesizer synthesizer;
private int startIndex;
private int endIndex;
Expand All @@ -41,35 +39,36 @@ public class AAC implements ActionListener {

/**
* Creates the AAC display for the file provided
* @param filename the name of the file that contains the
* images and text that will be in the AAC
*
* @param filename the name of the file that contains the images and text that will be in the AAC
*/
public AAC(String filename){
public AAC(String filename) {
this.aacMappings = new AACMappings(filename);
this.images = this.aacMappings.getImageLocs();
this.startIndex = 0;
this.endIndex = Math.min(NUM_ACROSS*NUM_DOWN, this.images.length);
frame=new JFrame();
frame.setPreferredSize(new Dimension(500,500));
loadImages(NUM_ACROSS,NUM_DOWN);
this.endIndex = Math.min(NUM_ACROSS * NUM_DOWN, this.images.length);
frame = new JFrame();
frame.setPreferredSize(new Dimension(500, 500));
loadImages(NUM_ACROSS, NUM_DOWN);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.pack();
frame.setVisible(true);
input = new Scanner(System.in);
}

/**
* Loads the images in the screen in a width by length grid
*
* @param width the number of images across to display
* @param length the number of images down to display
*/
public void loadImages(int width, int length) {
Container pane = frame.getContentPane();
pane.removeAll();

//add options to go to home screen
// add options to go to home screen
JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayout(1,3));
panel1.setLayout(new GridLayout(1, 3));

JButton home = new JButton(new ImageIcon("img/home.png"));
home.setActionCommand("");
Expand All @@ -87,43 +86,43 @@ public void loadImages(int width, int length) {
pane.add(panel1, BorderLayout.PAGE_START);


//if on page 2+, add back button
if(startIndex > 0) {
// if on page 2+, add back button
if (startIndex > 0) {
JButton backArrow = new JButton(new ImageIcon("img/back-to.png"));
backArrow.setActionCommand("back");
backArrow.addActionListener(this);
pane.add(backArrow, BorderLayout.LINE_START);
}

//add images
// add images
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(width,length));
panel.setLayout(new GridLayout(width, length));
int currImage = startIndex;
for(int y=0; y<length; y++){
for(int x=0; x<width; x++){
if(currImage < this.images.length) {
for (int y = 0; y < length; y++) {
for (int x = 0; x < width; x++) {
if (currImage < this.images.length) {
ImageIcon img = new ImageIcon(images[currImage]);
JButton button = new JButton(img);
button.setActionCommand(images[currImage]);
button.addActionListener(this);
panel.add(button);
panel.add(button);
currImage++;

}
}
}
pane.add(panel,BorderLayout.CENTER);
pane.add(panel, BorderLayout.CENTER);

//if have later pages, add next button
if(endIndex < images.length) {
// if have later pages, add next button
if (endIndex < images.length) {
JButton nextArrow = new JButton(new ImageIcon("img/next.png"));
nextArrow.setActionCommand("next");
nextArrow.addActionListener(this);
pane.add(nextArrow,BorderLayout.LINE_END);
pane.add(nextArrow, BorderLayout.LINE_END);
}

JLabel ack = new JLabel("All provided icons are from icons8: icons8.com");
pane.add(ack,BorderLayout.PAGE_END);
pane.add(ack, BorderLayout.PAGE_END);
pane.revalidate();
pane.requestFocusInWindow();
}
Expand All @@ -132,88 +131,79 @@ public static void main(String[] args) {

try {
// Set property as Kevin Dictionary
System.setProperty("freetts.voices","com.sun.speech.freetts.en.us"
+ ".cmu_us_kal.KevinVoiceDirectory");
System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us" + ".cmu_us_kal.KevinVoiceDirectory");

// Register Engine
Central.registerEngineCentral("com.sun.speech.freetts"
+ ".jsapi.FreeTTSEngineCentral");
synthesizer
= Central.createSynthesizer(
new SynthesizerModeDesc(Locale.US));
Central.registerEngineCentral("com.sun.speech.freetts" + ".jsapi.FreeTTSEngineCentral");
synthesizer = Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));

// Allocate synthesizer
synthesizer.allocate();

// Resume Synthesizer
synthesizer.resume();

}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
AAC aac = new AAC("AACMappings.txt");
}

/**
* Responds to the click of a button. If the button is a category or action
* (e.g. home, next), it updates the screen. If the button is an image within
* the category, it speaks aloud the text
* Responds to the click of a button. If the button is a category or action (e.g. home, next), it
* updates the screen. If the button is an image within the category, it speaks aloud the text
*/
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
System.out.println("Button clicked: "+actionCommand);
if(actionCommand.equals("back")) {
this.startIndex -= NUM_ACROSS*NUM_DOWN;
this.endIndex -= NUM_ACROSS*NUM_DOWN;
}
else if(actionCommand.equals("next")) {
this.startIndex += NUM_ACROSS*NUM_DOWN;
this.endIndex = Math.min(endIndex + NUM_ACROSS*NUM_DOWN, this.images.length);
}
else if(actionCommand.equals("save")) {
System.out.println("Button clicked: " + actionCommand);
if (actionCommand.equals("back")) {
this.startIndex -= NUM_ACROSS * NUM_DOWN;
this.endIndex -= NUM_ACROSS * NUM_DOWN;
} else if (actionCommand.equals("next")) {
this.startIndex += NUM_ACROSS * NUM_DOWN;
this.endIndex = Math.min(endIndex + NUM_ACROSS * NUM_DOWN, this.images.length);
} else if (actionCommand.equals("save")) {
this.aacMappings.writeToFile("AACMappingsNew.txt");
this.images = this.aacMappings.getImageLocs();
this.startIndex = 0;
this.endIndex = Math.min(NUM_ACROSS*NUM_DOWN, this.images.length);
}
else if(actionCommand.equals("add")) {
this.endIndex = Math.min(NUM_ACROSS * NUM_DOWN, this.images.length);
} else if (actionCommand.equals("add")) {
System.out.println("What is the image location");
String imageLoc = input.nextLine().trim();
System.out.println("What is the text");
String text = input.nextLine().trim();
this.aacMappings.add(imageLoc, text);
this.images = this.aacMappings.getImageLocs();
this.startIndex = 0;
this.endIndex = Math.min(NUM_ACROSS*NUM_DOWN, this.images.length);
}
else if(actionCommand.equals("")) {
this.endIndex = Math.min(NUM_ACROSS * NUM_DOWN, this.images.length);
} else if (actionCommand.equals("")) {
this.aacMappings.reset();
this.images = this.aacMappings.getImageLocs();
this.startIndex = 0;
this.endIndex = Math.min(NUM_ACROSS*NUM_DOWN, this.images.length);
}
else {
if(this.aacMappings.getCurrentCategory().equals("")) {
this.aacMappings.getText(actionCommand);
this.endIndex = Math.min(NUM_ACROSS * NUM_DOWN, this.images.length);
} else {
if (this.aacMappings.getCurrentCategory().equals("")) {
try {
this.aacMappings.getText(actionCommand);
} catch (KeyNotFoundException e1) {
e1.printStackTrace();
}
this.images = this.aacMappings.getImageLocs();
this.startIndex = 0;
this.endIndex = Math.min(NUM_ACROSS*NUM_DOWN, this.images.length);
}
else {
this.endIndex = Math.min(NUM_ACROSS * NUM_DOWN, this.images.length);
} else {
try {
String toSpeak = this.aacMappings.getText(actionCommand);
System.out.println("Spoke: "+toSpeak);
System.out.println("Spoke: " + toSpeak);
synthesizer.speakPlainText(toSpeak, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
}
catch (Exception e1) {
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
loadImages(NUM_ACROSS,NUM_DOWN);
loadImages(NUM_ACROSS, NUM_DOWN);

}

}
}
47 changes: 19 additions & 28 deletions src/TextSpeech.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,43 @@
// Java code to convert text to speech
// Code from: https://www.geeksforgeeks.org/converting-text-speech-java/

import java.util.Locale;
import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;

public class TextSpeech {

public static void main(String[] args)
{


public static void main(String[] args) {

try {
// Set property as Kevin Dictionary
System.setProperty(
"freetts.voices",
"com.sun.speech.freetts.en.us"
+ ".cmu_us_kal.KevinVoiceDirectory");

System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us" + ".cmu_us_kal.KevinVoiceDirectory");

// Register Engine
Central.registerEngineCentral(
"com.sun.speech.freetts"
+ ".jsapi.FreeTTSEngineCentral");

Central.registerEngineCentral("com.sun.speech.freetts" + ".jsapi.FreeTTSEngineCentral");

// Create a Synthesizer
Synthesizer synthesizer
= Central.createSynthesizer(
new SynthesizerModeDesc(Locale.US));

Synthesizer synthesizer = Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));

// Allocate synthesizer
synthesizer.allocate();

// Resume Synthesizer
synthesizer.resume();

// Speaks the given text
// until the queue is empty.
synthesizer.speakPlainText(
"GeeksforGeeks", null);
synthesizer.waitEngineState(
Synthesizer.QUEUE_EMPTY);

synthesizer.speakPlainText("GeeksforGeeks", null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);

// Deallocate the Synthesizer.
synthesizer.deallocate();
}

catch (Exception e) {
e.printStackTrace();
}
}
}
}
Loading