Reputation: 53
I dont understand this syntax error , insert ")" to complete MethodInvocation Syntax error, insert ";" to complete Statement at demojsapi.main(demojsapi.java:46)
I am actually working on a java project converting text to speesh with this code :
import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;
public class demojsapi
{
String speaktext;
public void dospeak(String speak,String voicename)
{
speaktext=speak;
String voiceName =voicename;
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++)
{
if (voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch (Exception e)
{
String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
System.out.println(""+e);
System.out.println(message);
}
}
public static void main(String[] args)
{
demojsapi obj=new demojsapi(); obj.despeak("shit","kevin16");
}
}
Upvotes: 3
Views: 49873
Reputation: 159864
The despeak
method does not exist. You should call dospeak
instead and with regular quotes:
obj.dospeak("foo", "kevin16");
Upvotes: 5
Reputation: 83
Very nicely explained Complete procedure with running code - Text To Speech in Java Using Freetts
Working Code :
import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;
public class Text2Speech
{
String speaktext;
public void dospeak(String speak,String voicename)
{
speaktext=speak;
String voiceName =voicename;
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++)
{
if (voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
System.out.print("Speaking : "+speaktext);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch (Exception e)
{
String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
System.out.println(""+e);
System.out.println(message);
}
}
public static void main(String[] args)
{
Text2Speech obj=new Text2Speech(); obj.dospeak("Hello i am kevin ","kevin16");
}
}
Upvotes: 1
Reputation: 1
please Download freetts-1.2.2-bin from google from given link and
http://sourceforge.net/projects/freetts/?source=directory
try my program in net beans
do not forget to add all jar files into your library folder code is given below. Its working .. my method ---
private static final String VOICENAME = "kevin16";
void mySpeak()
{
Voice voice;
VoiceManager vm = VoiceManager.getInstance();
voice = vm.getVoice(VOICENAME);
voice.allocate();
try{
voice.speak("Hi Mr Gaur Welcome to VITS. Thanks To choose Us");
}catch(Exception e){}
}
call this method from your inner code..
Upvotes: 5