Results 1 to 7 of 7
  1. #1
    mattcool is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default Help regarding first java program

    Hi,
    This is my first post in here.I am trying to run a java program which uses speech recognition but it require some corrections it is a java based notepad which has
    speech to text and text to speech conversion capabilities along with some commands feature.

    The external packages used are ocvolume and jsapi that are included in the attachment along with the code.
    Please correct the errors so that I can see the program working.
    Thank you. :)
    Attached Files Attached Files

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    That's not going to work. The people here prefer to help you correct your errors.

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    People here also are hesitant to download random codes/follow random links.

  4. #4
    mattcool is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    As you wish sir

    here goes the code

    ----------------------------------------------------------------------------

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import org.oc.ocvolume.*;
    import org.oc.ocvolume.audio.*;
    import javax.speech.Central;
    import javax.speech.synthesis.Synthesizer;
    import javax.speech.synthesis.SynthesizerModeDesc;
    import javax.speech.synthesis.Voice;
    import java.util.*;
    public class MyGUI
    implements ActionListener,Runnable
    Runtime r=Runtime.getRuntime();
    JFrame myFrame;
    JTextArea myArea;
    Font font;
    JTextField myText;
    //menu section
    JMenuBar menu;
    JMenu file;
    JMenu edit;
    JMenu fontStyle;
    JMenuItem new1;
    JMenuItem open;
    JMenuItem save;
    JButton record;
    JMenu option;
    JMenuItem commands;
    JMenuItem wText;
    JMenuItem verify;
    JMenuItem bold;
    JMenuItem italic;
    JMenuItem plain;
    JMenu fontSize;
    JMenuItem f10;
    JMenuItem f20;
    JMenuItem f30;
    JMenuItem copy;
    JMenuItem paste;
    JMenuItem cut;
    JMenuItem sel;
    //synthesizer part
    String voiceName;
    SynthesizerModeDesc desc;
    Synthesizer synthesizer;
    Voice[] voices;
    Voice voice;
    boolean comm=false;
    JFileChooser fc=new JFileChooser();
    private ocvolume engine = new ocvolume("dict", "");
    private micInput mic = new micInput();
    private Thread checking;
    public void myDesign(){ //design function
    myFrame=new JFrame("INTERACTIVE NOTEPAD");
    Container c=myFrame.getContentPane();
    c.setLayout(new BorderLayout());
    record=new JButton("Record");
    myArea=new JTextArea();
    myArea.setLineWrap(true);
    JScrollPane bar=new JScrollPane(myArea);
    myText=new JTextField();
    font=new Font("abc",10,3);
    menu=new JMenuBar();
    file=new JMenu("File");
    file.setMnemonic('f');
    option=new JMenu("Option");
    option.setMnemonic('o');
    edit=new JMenu("Edit");
    edit.setMnemonic('e');
    new1=new JMenuItem("New");
    open=new JMenuItem("Open");
    save=new JMenuItem("save");
    commands =new JMenuItem("Commands");
    wText=new JMenuItem("Writing Text");
    verify=new JMenuItem("Verify");
    fontStyle=new JMenu("Font Style");
    bold=new JMenuItem("Bold");
    italic=new JMenuItem("Italic");
    plain=new JMenuItem("Plain");
    fontSize=new JMenu("FontSize");
    f10=new JMenuItem("10");
    f20=new JMenuItem("20");
    f30=new JMenuItem("30");
    copy=new JMenuItem("Copy");
    paste=new JMenuItem("Paste");
    cut=new JMenuItem("Cut");
    sel =new JMenuItem ("Select All");
    new1.addActionListener(this);
    open.addActionListener(this);
    save.addActionListener(this);
    record.addActionListener(this);
    commands.addActionListener(this);
    wText.addActionListener(this);
    verify.addActionListener(this);
    bold.addActionListener(this);
    italic.addActionListener(this);
    plain.addActionListener(this);
    copy.addActionListener(this);
    paste.addActionListener(this);
    cut.addActionListener(this);
    sel.addActionListener(this);
    f10.addActionListener(this);
    f20.addActionListener(this);
    f30.addActionListener(this);
    new1.setAccelerator(KeyStroke.getKeyStroke(KeyEven t.VK_N,
    ActionEvent.CTRL_MASK));
    open.setAccelerator(KeyStroke.getKeyStroke(KeyEven t.VK_O,
    ActionEvent.CTRL_MASK));
    save.setAccelerator(KeyStroke.getKeyStroke(KeyEven t.VK_S,
    ActionEvent.CTRL_MASK));
    cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_X,
    ActionEvent.CTRL_MASK));
    copy.setAccelerator(KeyStroke.getKeyStroke(KeyEven t.VK_C,
    ActionEvent.CTRL_MASK));
    paste.setAccelerator(KeyStroke.getKeyStroke(KeyEve nt.VK_V,
    ActionEvent.CTRL_MASK));
    sel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_A,
    ActionEvent.CTRL_MASK));
    file.add(new1);
    file.add(open);
    file.add(save);
    option.add(commands);
    option.add(wText);
    option.add(verify);
    fontSize.add(f10);
    fontSize.add(f20);
    fontSize.add(f30);
    edit.add(cut);
    edit.add(copy);
    edit.add(paste);
    edit.add(sel);
    fontStyle.add(bold);
    fontStyle.add(italic);
    fontStyle.add(plain);
    edit.add(fontSize);
    edit.add(fontStyle);
    menu.add(file);
    menu.add(edit);
    menu.add(option);
    c.add(menu,BorderLayout.NORTH);
    c.add(bar,BorderLayout.CENTER);
    c.add(record,BorderLayout.EAST);
    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CL OSE);
    myFrame.setSize(400,400);
    myFrame.setVisible(true);
    }//end of Design

    MyGUI(){
    synthinit();
    myDesign();
    }//end of the constructor
    public void actionPerformed(ActionEvent e){
    if(e.getSource()==sel){
    myArea.selectAll();
    }
    if(e.getSource()==copy){
    myArea.copy();
    }
    if(e.getSource()==paste){
    myArea.paste();
    }
    if(e.getSource()==cut){
    myArea.cut();
    }
    if(e.getSource()==bold){
    int c1=Font.BOLD;
    font=font.deriveFont(c1);
    myArea.setFont(font);
    }
    if(e.getSource()==italic){
    int c1=Font.ITALIC;
    font=font.deriveFont(c1);
    myArea.setFont(font);
    }
    if(e.getSource()==plain){
    myArea.setFont(null);
    }
    if(e.getSource()==f10){
    float c1=(float)10.0;
    font=font.deriveFont(c1);
    myArea.setFont(font);
    }
    if(e.getSource()==f20){
    float c1=(float)20.0;
    font=font.deriveFont(c1);
    myArea.setFont(font);
    }
    if(e.getSource()==f30){
    float c1=(float)30.0;
    font=font.deriveFont(c1);
    myArea.setFont(font);
    }
    if(e.getSource()==verify){
    String str = new String(myArea.getText());//String to be spoken
    synthesizer.speakPlainText(str, null);
    }
    if(e.getSource()==commands){
    comm=true;
    }//end of commands event
    if(e.getSource()==wText){
    comm=false;
    }//end of writing text event
    if(e.getSource()==record){
    if ( record.getLabel().equals("Record") == true ){
    record.setLabel("Stop");
    mic = new micInput();
    mic.start();
    try{
    checking.stop();
    }
    catch(NullPointerException e1){}
    checking = new Thread(this);
    checking.start();
    }
    else if ( record.getLabel().equals("Stop") == true ){
    record.setLabel("Record");
    mic.stopRecord();
    }
    }// end of record button event
    if (e.getSource()==new1){
    if(!myArea.getText().equals("")){
    String str = new String("do u want to save this document");//String to be spoken
    synthesizer.speakPlainText(str, null);
    int ch=JOptionPane.showConfirmDialog(null,"do u want to save this document");
    if(ch==0){
    saveFile();}}
    String str = new String("your document is cleared ");//String to be spoken
    synthesizer.speakPlainText(str, null);
    myArea.setText("");
    }// end of new1 event
    else if (e.getSource()==open){
    if(!myArea.getText().equals("")){
    String str = new String("do u want to save this document");//String to be spoken
    synthesizer.speakPlainText(str, null);
    int ch=JOptionPane.showConfirmDialog(null,"do u want to save this document");
    if(ch==0){
    saveFile();
    }}
    String str = new String("you have selected open option ");//String to be spoken
    synthesizer.speakPlainText(str, null);
    openFile();
    }// end of open event
    else if (e.getSource()==save){
    String str = new String(" you have selected save option");//String to be spoken
    synthesizer.speakPlainText(str, null);
    saveFile();
    }// end of save event
    }// end of actionperformed method
    public void saveFile()
    {
    int returnVal = fc.showSaveDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //this is where a real application would open the file.
    try{
    FileWriter fw = new FileWriter(file);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(myArea.getText());
    bw.close();
    }
    catch(Exception ex){}
    }
    }// end of savefile method
    public void openFile(){
    int returnVal = fc.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //this is where a real application would open the file.
    try{
    FileReader fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);
    String temp = "";
    myArea.setText("");
    while( (temp = br.readLine()) != null ){
    myArea.append(temp + "\n");
    }
    br.close();
    }
    catch(Exception e){}
    }
    }// end of openFile method
    public void run(){
    while(true){
    mic.removeOldWord();
    while(!mic.byteArrayComplete()){
    try{
    checking.sleep(200);
    }
    catch(Exception e){
    e.printStackTrace();
    }
    }
    mic.newWord();
    short recordedSample[] = mic.returnShortArray();
    String recognizedWord = engine.getWord(recordedSample);
    if(comm==true){
    if(recognizedWord.equals("save"))
    {
    String str = new String("you have selected save option");//String to be spoken
    synthesizer.speakPlainText(str, null);
    saveFile();
    }// end of save
    else if(recognizedWord.equals("open"))
    {
    if(!myArea.getText().equals("")){
    String str = new String("do u want to save this document");//String to be spoken
    synthesizer.speakPlainText(str, null);
    int ch=JOptionPane.showConfirmDialog(null,"do u want to save this document");
    if(ch==0){
    saveFile();
    }}
    String str = new String("you have selected open option");//String to be spoken
    synthesizer.speakPlainText(str, null);
    openFile();
    }// end of open
    else
    if(recognizedWord.equals("Mspaint")||recognizedWor d.equals("Notepad")||recognizedWtry{r.exec(recogni zedWord);
    }
    catch(Exception ew){}
    }ord.equals("calc"))
    {
    else if(recognizedWord.equals("clear")){
    String str = new String("your document is now cleared ");//String to be spoken
    synthesizer.speakPlainText(str, null);
    myArea.setText("");
    }
    else if(recognizedWord.equals("selectall")){
    myArea.selectAll();
    }
    else if(recognizedWord.equals("copy")){
    myArea.copy();else if(recognizedWord.equals("paste")){
    myArea.paste();
    }
    }//end of commands if
    else
    myArea.append(recognizedWord + " ");
    }
    }// end of mic function
    public void synthinit(){
    try{
    voiceName = new String("kevin16");
    desc = new SynthesizerModeDesc(
    null, // engine name
    "general", // mode name
    Locale.US, // locale
    null, // running
    null); // voice
    synthesizer = Central.createSynthesizer(desc);
    if (synthesizer == null) {
    System.exit(1);
    }
    synthesizer.allocate();
    synthesizer.resume();
    desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
    voices = desc.getVoices();
    voice = null;
    for (int i = 0; i < voices.length; i++)
    {
    if (voices[i].getName().equals(voiceName))
    {
    voice = voices[i];
    break;
    }
    }
    if (voice == null)
    {
    System.err.println("Synthesizer does not have a voice named "+voiceName+ ".");
    System.exit(1);
    }
    synthesizer.getSynthesizerProperties().setVoice(vo ice);
    }
    catch(Exception ee){}
    }// end of synthesizer function
    public static void main(String args[]){
    MyGUI a=new MyGUI();
    }// end of main
    }//end of class MyGUI

    --------------------------------------------------------------------------

    and here are the compile error messages from jgrasp

    --------------------------------------------------------------------------

    ----jGRASP exec: javac -g myGUI.java

    myGUI.java:319: ')' expected
    if(recognizedWord.equals("Mspaint")||recognizedWor d.equals("Notepad")||recognizedWord.equals("calc")
    ^
    myGUI.java:323: ';' expected
    }Word.equals("calc"))
    ^
    myGUI.java:325: 'else' without 'if'
    else if(recognizedWord.equals("clear")){
    ^
    myGUI.java:334: 'else' without 'if'
    myArea.copy();else if(recognizedWord.equals("paste")){
    ^
    myGUI.java:342: illegal start of expression
    public void synthinit(){
    ^
    myGUI.java:342: illegal start of expression
    public void synthinit(){
    ^
    myGUI.java:342: ';' expected
    public void synthinit(){
    ^
    myGUI.java:376: illegal start of expression
    public static void main(String args[])
    ^
    myGUI.java:376: illegal start of expression
    public static void main(String args[])
    ^
    myGUI.java:376: ';' expected
    public static void main(String args[])
    ^
    myGUI.java:376: ')' expected
    public static void main(String args[])
    ^
    myGUI.java:376: illegal start of expression
    public static void main(String args[])
    ^
    myGUI.java:376: ';' expected
    public static void main(String args[])
    ^
    myGUI.java:376: illegal start of expression
    public static void main(String args[])
    ^
    myGUI.java:376: ';' expected
    public static void main(String args[])
    ^
    15 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    --------------------------------------------------------------------------
    Now can you please help

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    If you format your code and read the error messages you'll be able to know what is wrong and how to fix it.

  6. #6
    mattcool is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    Thanks r035198x
    errors have been reduced to 7.I will recheck and post later
    Thanks :)

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Please also wrap your code in code tags. You can do this by putting code tags before and after your program
    [ code] //don't put the space
    YOUR CODE HERE
    [/code]

    Also, ask specific questions, people are also hesitant to study your code and get an understanding of WHAT the code is doing. Include what you have done to try and fix these errors as well.

Similar Threads

  1. Call one Java Program from another Java Program
    By rajpalparyani in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 05:13 AM
  2. Replies: 4
    Last Post: 07-30-2010, 01:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 06:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •