Skip to content

Commit

Permalink
Final working prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
ipar569 authored Sep 23, 2016
1 parent ea2b39d commit 641f216
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 44 deletions.
7 changes: 5 additions & 2 deletions Festival.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public class Festival extends SwingWorker<Void, Integer>{
private String _tts;
private String _voice;

//Getting the values to be used.
public Festival(String tts,String voice) throws Exception{
_tts=tts;
_voice = voice;
}

//When it is executed, festival is played.
@Override
protected Void doInBackground() throws Exception {
setScheme(_tts, _voice);
Expand Down Expand Up @@ -49,14 +51,15 @@ private void setScheme(String tts, String voice) throws IOException{
Writer output;
output = new BufferedWriter(new FileWriter(failed,false));
output.append("(voice_"+_voice+")\n");
output.append("(Parameter.set 'Duration_Stretch 1.1)");
String[] lines = tts.split(" ");
output.append("(Parameter.set 'Duration_Stretch 1.2)");
String[] lines = tts.split("!!");
for(int i =0; i<lines.length;i++){
output.append("(SayText \""+lines[i]+"\")");
}
output.close();
}

//Get the list of available voice on the current machine.
public ArrayList<String> listOfVoices() throws Exception{
ArrayList<String> voice = new ArrayList<String>();

Expand Down
23 changes: 11 additions & 12 deletions Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import javax.swing.SwingUtilities;

/*
* Author: Injae Park
* Author: Injae Park and Jack Huang
*/

public class Main extends JFrame implements ActionListener {
Expand Down Expand Up @@ -55,7 +55,7 @@ public Main() {

//label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("Arial",Font.BOLD, 18));
label.setBounds(100, 10, 500, 60);
label.setBounds(120, 10, 500, 60);
label2.setBounds(230, 50, 200, 30);
titlePanel.setLayout(null);
//label2.setVerticalAlignment(SwingConstants.BOTTOM);
Expand Down Expand Up @@ -103,12 +103,7 @@ public void setTitle(){
label2.setText("Level "+_level);
}

private void menu() {
getContentPane().removeAll();
getContentPane().add(menuPanel);
revalidate();
repaint();
}


public void actionPerformed(ActionEvent e) {
//Finding the button where the action event occured i.e. finding
Expand Down Expand Up @@ -180,18 +175,20 @@ public void actionPerformed(ActionEvent e) {
}

}

/*
* This functions makes the table using the ViewAccuracy class. Table is placed in a
* new JPanel.
*/
protected void makeTable() {
ViewAccuracy va = new ViewAccuracy();
JTable table = new JTable(va);
final JFrame fr = new JFrame();
fr.setSize(500,500);
fr.setVisible(true);
//Create panels for Statistics. Add table to panel.
JPanel statsPanel = new JPanel();
//Add a close button to close the frame
JButton returnBtn = new JButton("Close Stats");
statsPanel.setLayout(new BorderLayout());
//statsPanel.add(_statLabel, BorderLayout.NORTH);
statsPanel.add(new JScrollPane(table), BorderLayout.CENTER);
returnBtn.addActionListener(new ActionListener() {

Expand Down Expand Up @@ -248,7 +245,9 @@ private void clearStats() throws IOException{
}
createAccuracy();
}


//Creates save files to store the accuracy, then add zeros to the file. There is a save
//file for each level
private void createAccuracy() {

for (int i = 1; i <= 11; i++) {
Expand Down
13 changes: 7 additions & 6 deletions MediaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MediaPlayer {
RuntimeUtil.getLibVlcLibraryName(), "/Applications/vlc-2.0.0/VLC.app/Contents/MacOS/lib"
);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

//Make media player
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

final EmbeddedMediaPlayer video = mediaPlayerComponent.getMediaPlayer();
Expand All @@ -47,6 +47,8 @@ public class MediaPlayer {
panel.add(mediaPlayerComponent, BorderLayout.CENTER);

mediaFrame.setContentPane(panel);

//add pause button and a progress bar
final JButton pauseBtn = new JButton("Pause");

JPanel secondPanel = new JPanel(new GridLayout(2,1));
Expand All @@ -70,26 +72,25 @@ public void actionPerformed(ActionEvent e) {
}

});


//Progress Bar shows how long the video has been playing
Timer timer = new Timer(50, new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
long time = (long) video.getTime();
//System.out.println(time);
long totalTime = (long) video.getLength();
//System.out.println(totalTime);
long percentage = ( (time * 100) / totalTime );
int n = (int) percentage;
//System.out.println(percentage);
pb.setValue(n);
}

});

timer.start();
mediaPath = "big_buck_bunny_1_minute.avi";


//Video stops playing after frame closes
mediaFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Expand Down
53 changes: 33 additions & 20 deletions Quiz.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Quiz extends JFrame implements ActionListener {
private JButton btn = new JButton("Submit");
private JButton speak = new JButton("Listen Again");
private JButton spelling = new JButton("Listen to Spelling");
private JLabel score;
private int _testNo=1;
private int _wc;
private JLabel label,label1,label2;
Expand All @@ -45,6 +46,7 @@ public class Quiz extends JFrame implements ActionListener {
private ArrayList<String> _testList = new ArrayList<String>();
private int _maxNum;
private int _level;
private int _testNum;

private int _attempts;
private int _fails;
Expand All @@ -69,7 +71,7 @@ public Quiz(String file,Main main,int level) throws Exception {

//Setting the size and layout of the spelling quiz
setSize(500,500);
setLayout(new GridLayout(4,1));
setLayout(new GridLayout(5,1));
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.getRootPane().setDefaultButton(btn);

Expand Down Expand Up @@ -103,9 +105,11 @@ public Quiz(String file,Main main,int level) throws Exception {
//Choosing the number of quiz depending on the word count
String tts = "";
if(_wc<_maxNum){
_testNum=_wc;
tts="Spell word 1 of "+_wc+": ";
label = new JLabel(tts);
}else{
_testNum = _maxNum;
tts="Spell word 1 of "+_maxNum+": ";
label = new JLabel(tts);
}
Expand All @@ -130,17 +134,25 @@ public Quiz(String file,Main main,int level) throws Exception {
middle.add(speak);
if(_maxNum==5){
middle.add(spelling);
}
}

score = new JLabel(_correct+" out of "+_testNum);
score.setHorizontalAlignment(SwingConstants.CENTER);

//Adding labels and pane to the main frame.
add(label1);
add(middle);
add(label2);
add(score);
bottom.add(label3);
bottom.add(_selectVoices);
bottom.add(stats);
add(bottom);





_selectVoices.addActionListener(this);

//Adding action listeners to the button.
Expand All @@ -150,7 +162,7 @@ public Quiz(String file,Main main,int level) throws Exception {
stats.addActionListener(this);

//Speaking out instruction to start and the word to be tested.
festival(_testList.get(_testNo-1)+".");
festival("Spell "+_testList.get(_testNo-1)+".");

}

Expand All @@ -164,16 +176,18 @@ public void actionPerformed(ActionEvent e) {
return;
}
try{
//If user pressed speak button, spelling of the word
//If user pressed speak button, the word
//is spoken by festival.
JButton button = (JButton) e.getSource();
if (button.equals(speak)){

festival(_testList.get(_testNo-1));
return;
//if spelling is pressed, the alphabet of the word being tested is spoken.
}else if (button.equals(spelling)){
festivalAlphabet(_testList.get(_testNo-1));
return;
//open up the stats view.
}else if (button.equals(stats)){
_main.makeTable();
return;
Expand All @@ -187,15 +201,6 @@ public void actionPerformed(ActionEvent e) {
removeFailed(_testList.get(_testNo-1));


//If user gets incorrect first time, the word is added to faulted list
/*if(incorrect==1){
faulted();
//else the word is added to teh mastered list
}else{
mastered();
} */

//Increase the test number
_attempts++;
_testNo++;
_correct++;
Expand All @@ -213,16 +218,17 @@ public void actionPerformed(ActionEvent e) {
if(incorrect<1){
//Setting message to the user about the fault
label2.setText("Incorrect, please try again!!");
festival("Incorrect!! "+_testList.get(_testNo-1)+".");
festival("Incorrect!! Spell"+_testList.get(_testNo-1)+".");
//Word is spoken again.
incorrect++;
txt.setText("");
return;
//First time failing
}else{
//Result message to user
label2.setText("Failed Test!!");

label2.setText("Failed!!");

//increase test number and fail value
_attempts++;
_fails++;

Expand All @@ -242,7 +248,8 @@ public void actionPerformed(ActionEvent e) {

}
}

//updating the values.
score.setText(_correct+" out of "+_testNum);
updateAccuracy();
//Clearing the Jtext field
txt.setText("");
Expand All @@ -256,20 +263,22 @@ public void actionPerformed(ActionEvent e) {
_main.setVisible(true);
dispose();
}else{
//opens options menu where user can choose their next action.
SubMenu sub = new SubMenu(_file,_main,_level,_correct,_testNo-1);
sub.setVisible(true);
dispose();
}

}else{
//Continue the quiz
festival(label2.getText()+" "+_testList.get(_testNo-1)+".");
festival(label2.getText()+" Spell "+_testList.get(_testNo-1)+".");
}
}catch(Exception excep){
excep.printStackTrace();
}
}

//Function that allows user to change the voice of festival.
private JComboBox<String> selectVoice() throws Exception{

Festival f = new Festival("","");
Expand All @@ -284,7 +293,8 @@ private JComboBox<String> selectVoice() throws Exception{

return voices;
}


//method to change the voice.
private void changeVoice(String voice) throws IOException{
File failed = new File(".festivalrc");
//If file does not exist, create new file
Expand Down Expand Up @@ -335,7 +345,8 @@ private void setTestList(WordList wordlist) throws IOException{
_testList = wordlist.createTestList(_level,_maxNum);
}


//Obtains the accuracy values from the save file (for the current quiz level)
// then add the levels to the corresponding fields
private void getAccuracy() throws IOException {
File accuracy = new File(".accuracy_" + _level);
if (! accuracy.exists()) {
Expand All @@ -352,6 +363,8 @@ private void getAccuracy() throws IOException {

}
}
//Write the values from the accuracy fields (_attempts, _fails) to the corresponding
// save files
private void updateAccuracy() throws IOException {
File accuracy = new File(".accuracy_" + _level);

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# VOXSPELL
# VOXSPELL

WARNING!! Before you excute the program, make sure that "NZCER-spelling-lists.txt" and "big_buck_bunny_1_minute.avi" is in the same folder with voxspell.jar.

1. Put the excutable jar file called "voxspell.jar" and wordlist file in your working/current directory.
2. Go into the current directory via terminal using cd command.
3. run the jar file using the command: java -jar voxspell.jar
6 changes: 3 additions & 3 deletions ViewAccuracy.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ViewAccuracy extends AbstractTableModel{


public ViewAccuracy() {

//This for loop reads all accuracy save files and adds the values to some lists
for (int i = 1; i <= 11; i++) {
try {
FileReader fr = new FileReader(".accuracy_" + i);
Expand All @@ -33,7 +33,7 @@ public ViewAccuracy() {
e.printStackTrace();
}
}

//This for loop calculates the overall accuracy (as a percentage) for all levels
for (int j = 0; j < 11; j++) {
double num = 0;
if (attemptsList.get(j) != 0) {
Expand All @@ -60,7 +60,7 @@ public int getColumnCount() {
return 4;

}

//Add values from the arraylists into the table
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
Expand Down
Loading

0 comments on commit 641f216

Please sign in to comment.