import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.speech.freetts.*;  // imports the Voice and VoiceManager classes

public class ButtonSpeechTest extends JFrame implements ActionListener
{
public String Characters[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "EXIT", "HELLO" };
public JButton butts[ ] = new JButton[  Characters.length ]; //creates the array
public Voice helloVoice;   // a Voice!  

public ButtonSpeechTest()
   {
   setSize( 500, 200 );
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setLayout (new FlowLayout());
   
	// the author of the Voice class says to do all these things:
	String voiceName = "kevin16";   // what kind of Voice?
   VoiceManager voiceManager = VoiceManager.getInstance();
   helloVoice = voiceManager.getVoice(voiceName);
   helloVoice.allocate();     // Allocates the resources for the voice.
 
	for( int x=0; x<butts.length; x++)
      {
      butts[x] = new JButton( Characters[x] ); 
	   add( butts[x] );
      butts[x].addActionListener(this);
	   }

   setVisible(true);	
   }
	 
public static void main (String [] args)
   {
   ButtonSpeechTest app = new ButtonSpeechTest();
   }

public void actionPerformed ( ActionEvent e ) 
   {
   System.out.println("Action: " + e.getActionCommand( ));  // use e.getActionCommand( ); to print button label

   // Synthesize speech.
   helloVoice.speak( e.getActionCommand() );
	
   if (e.getActionCommand().equals("EXIT"))
	  {
     //Clean up and leave.
     helloVoice.deallocate();
     System.exit(0);
	  }
   } // end actionPerformed method
   
} // end class

