Jump to content
Sign in to follow this  
alienA2

Speech Recognition/Synthesizer Script not running

Recommended Posts

Hi I am trying to run this program that was made for speech recognition. However, it does not run.Tools used: notepadd++; Command Prompt Here is the errors:C:\java_work\JavaVoice>javac JavaVoice.javaJavaVoice.java:14: error: package javax.speech does not existimport javax.speech.AudioException; ^JavaVoice.java:15: error: package javax.speech does not existimport javax.speech.Central; ^JavaVoice.java:16: error: package javax.speech does not existimport javax.speech.EngineException; ^JavaVoice.java:17: error: package javax.speech.synthesis does not existimport javax.speech.synthesis.Synthesizer; ^JavaVoice.java:18: error: package javax.speech.synthesis does not existimport javax.speech.synthesis.SynthesizerModeDesc; ^JavaVoice.java:32: error: cannot find symbol private Synthesizer synth; ^ symbol: class Synthesizer location: class JavaVoiceJavaVoice.java:42: error: package javax.speech does not exist javax.speech.EngineList elist = Central.availableSyntizers(null); ^JavaVoice.java:42: error: cannot find symbol javax.speech.EngineList elist = Central.availableSyntizers(null); ^ symbol: variable Central location: class JavaVoiceJavaVoice.java:46: error: cannot find symbol SynthesizerModeDesc desc = (SynthesizerModeDeelist.elementAt(i); ^ symbol: class SynthesizerModeDesc location: class JavaVoiceJavaVoice.java:46: error: cannot find symbol SynthesizerModeDesc desc = (SynthesizerModeDeelist.elementAt(i); ^ symbol: class SynthesizerModeDesc location: class JavaVoiceJavaVoice.java:50: error: cannot find symbol synth = Central.createSynthesizer((SynthesizerModeDeslist.get(preferences.get("voice.selected",""))); ^ symbol: class SynthesizerModeDesc location: class JavaVoiceJavaVoice.java:50: error: cannot find symbol synth = Central.createSynthesizer((SynthesizerModeDeslist.get(preferences.get("voice.selected",""))); ^ symbol: variable Central location: class JavaVoiceJavaVoice.java:54: error: cannot find symbol catch(EngineException ex) { ^ symbol: class EngineException location: class JavaVoiceJavaVoice.java:57: error: cannot find symbol catch(AudioException ex) { ^ symbol: class AudioException location: class JavaVoiceJavaVoice.java:129: error: cannot find symbol synth = Central.createSynthesizer((SyesizerModeDesc) list.get(str)); ^ symbol: class SynthesizerModeDescJavaVoice.java:129: error: cannot find symbol synth = Central.createSynthesizer((SyesizerModeDesc) list.get(str)); ^ symbol: variable CentralJavaVoice.java:133: error: cannot find symbol catch(EngineException ex) { ^ symbol: class EngineExceptionJavaVoice.java:136: error: cannot find symbol catch(AudioException ex) { ^ symbol: class AudioExceptionJavaVoice.java:149: error: cannot find symbol catch(EngineException ex) { ^ symbol: class EngineExceptionJavaVoice.java:182: error: cannot find symbol SynthesizerModeDesc desc1 = (SynthesizerModeDesc) obj1; ^ symbol: class SynthesizerModeDesc location: class JavaVoiceJavaVoice.java:182: error: cannot find symbol SynthesizerModeDesc desc1 = (SynthesizerModeDesc) obj1; ^ symbol: class SynthesizerModeDesc location: class JavaVoiceJavaVoice.java:183: error: cannot find symbol SynthesizerModeDesc desc2 = (SynthesizerModeDesc) obj2; ^ symbol: class SynthesizerModeDesc location: class JavaVoiceJavaVoice.java:183: error: cannot find symbol SynthesizerModeDesc desc2 = (SynthesizerModeDesc) obj2; ^ symbol: class SynthesizerModeDesc location: class JavaVoiceJavaVoice.java:194: error: cannot find symbol catch(EngineException ex) { ^ symbol: class EngineException location: class JavaVoice.AppCloserNote: JavaVoice.java uses unchecked or unsafe operations.Note: Recompile with -Xlint:unchecked for details.24 errors Here is the code:import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.util.Collections;import java.util.Comparator;import java.util.Locale;import java.util.Hashtable;import java.util.prefs.Preferences;import javax.speech.AudioException;import javax.speech.Central;import javax.speech.EngineException;import javax.speech.synthesis.Synthesizer;import javax.speech.synthesis.SynthesizerModeDesc;import javax.swing.DefaultComboBoxModel;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.JTextArea;import javax.swing.JToolBar;public class JavaVoice extends JFrame implements Comparator { private Synthesizer synth; private File readFile = null; Preferences preferences = Preferences.userRoot().node("dlb/JavaVoice"); JComboBox voices; Hashtable list; public JavaVoice() { super("Java Voice Synthesizer"); addWindowListener(new AppCloser()); DefaultComboBoxModel model = new DefaultComboBoxModel(); try { javax.speech.EngineList elist = Central.availableSynthesizers(null); list = new Hashtable(elist.size()); Collections.sort(elist,this); for (int i=0;i<elist.size();i++) { SynthesizerModeDesc desc = (SynthesizerModeDesc)elist.elementAt(i); model.addElement(desc.getModeName()); list.put(desc.getModeName(),desc); } synth = Central.createSynthesizer((SynthesizerModeDesc) list.get(preferences.get("voice.selected",""))); synth.allocate(); synth.resume(); } catch(EngineException ex) { ex.printStackTrace(); } catch(AudioException ex) { ex.printStackTrace(); } final JTextArea textArea = new JTextArea(); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); JScrollPane scrollPane = new JScrollPane(textArea); getContentPane().add(scrollPane,BorderLayout.CENTER); JToolBar toolBar = new JToolBar(); JButton button = new JButton("Open"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { JFileChooser fileChooser = new JFileChooser(preferences.get("voice.openDirectory",System.getProperty("user.dir"))); if(fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { readFile = fileChooser.getSelectedFile(); preferences.put("voice.openDirectory",readFile.getParent()); try { FileReader reader = new FileReader(readFile); textArea.read(reader,readFile.getName()); reader.close(); } catch(IOException ex) { ex.printStackTrace(); } } } }); toolBar.add(button); button = new JButton("Clear"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { textArea.setText(""); } }); toolBar.add(button); toolBar.add(button); button = new JButton("Start"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String str = textArea.getSelectedText(); if(str != null && str.length() > 0) { synth.speakPlainText(str.toLowerCase(),null); textArea.setSelectionStart(0); textArea.setSelectionEnd(0); } else { str = textArea.getText(); synth.speakPlainText(str.toLowerCase(),null); } } }); toolBar.add(button); button = new JButton("Stop"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { synth.cancel(); } catch(ArrayIndexOutOfBoundsException ex) {} } }); toolBar.add(button); toolBar.addSeparator(); toolBar.add(new JLabel("Voice:")); voices = new JComboBox(model); voices.setSelectedItem(preferences.get("voice.selected","")); voices.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { synth.deallocate(); String str = (String) voices.getSelectedItem(); preferences.put("voice.selected",str); synth = Central.createSynthesizer((SynthesizerModeDesc) list.get(str)); synth.allocate(); synth.resume(); } catch(EngineException ex) { ex.printStackTrace(); } catch(AudioException ex) { ex.printStackTrace(); } } }); toolBar.add(voices); toolBar.addSeparator(); button = new JButton("Exit"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { synth.deallocate(); } catch(EngineException ex) { ex.printStackTrace(); } preferences.putInt("voice.mainWindow.x",getLocation().x); preferences.putInt("voice.mainWindow.y",getLocation().y); preferences.putInt("voice.mainWindow.width",getSize().width); preferences.putInt("voice.mainWindow.height",getSize().height); System.exit(1); } }); toolBar.add(button); getContentPane().add(toolBar,BorderLayout.NORTH); final JTextField textField = new JTextField(); textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String txt = textField.getText(); if(txt.length() > 0) { textArea.append(txt+'\n'); synth.speakPlainText(txt, null); textField.setText(""); } } }); getContentPane().add(textField,BorderLayout.SOUTH); int x = preferences.getInt("voice.mainWindow.x",1); int y = preferences.getInt("voice.mainWindow.y",1); int width = preferences.getInt("voice.mainWindow.width",640); int height = preferences.getInt("voice.mainWindow.height",480); setLocation(x,y); setSize(width,height); setVisible(true); } public int compare(Object obj1, Object obj2) { SynthesizerModeDesc desc1 = (SynthesizerModeDesc) obj1; SynthesizerModeDesc desc2 = (SynthesizerModeDesc) obj2; return desc1.getModeName().compareToIgnoreCase(desc2.getModeName()); } public static void main(String args[]) { new JavaVoice(); } class AppCloser extends WindowAdapter { public void windowClosing(WindowEvent ev) { try { synth.deallocate(); } catch(EngineException ex) { ex.printStackTrace(); } System.exit(1); } }}

Share this post


Link to post
Share on other sites

Hi, maybe u fixed it already :rolleyes: I try code above, following http://www.ryan-h.com/uncategorized/java-speech-jsapi-freetts/ and stops at this error (with the GUI built successfully) "System property "mbrola.base" is undefined. Will not use MBROLA voices." Just one notice, saw deep inside this line: javax.speech.EngineList elist = Central.availableSynthesizers(null); (with Java Decompiler tool for the Central.class), it call loadProps() function with the content below: private static final synchronized void loadProps() { if(loadedProperties) return; loadedProperties = true; String s = File.separator; String as[] = new String[2]; as[0] = System.getProperty("user.home") + s + "speech.properties"; as[1] = System.getProperty("java.home") + s + "lib" + s + "speech.properties"; for(int i = 0; i < as.length; i++) { String s1 = as; Properties properties = new Properties(); File file = new File(s1); try { FileInputStream fileinputstream = new FileInputStream(file); properties.load(new BufferedInputStream(fileinputstream)); fileinputstream.close(); } catch(FileNotFoundException _ex) { } catch(IOException _ex) { } for(Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements();) { String s2 = (String)enumeration.nextElement(); if(s2.endsWith("EngineCentral")) { String s3 = properties.getProperty(s2); try { registerEngineCentral(s3); } catch(EngineException _ex) { } } } } } So be sure to put the speech.properties in the right directory (try to print out System.getProperty("user.home") to get the location)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×