Java Speech
jeg har hentet free tts fra http://freetts.sourceforge.net/docs/index.phpjeg kan compile koden uden problemmer men når jeg prøver at kører den får jeg følgende fejl:
Can't find synthesizer.
Make sure that there is a "speech.properties" file at either of these locations:
user.home: C:\Documents and Settings\Henrik
java.home: C:\j2re1.4.0_01\lib
jeg har placeret speech.properties filen begge steder så jeg ved ikke hvor fejlen er håber at nogen kan hjælpe mig.
her er koden:
import java.io.File;
import java.util.Locale;
import javax.speech.Central;
import javax.speech.Engine;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.SynthesizerProperties;
import javax.speech.synthesis.Voice;
public class Speech
{
Synthesizer synthesizer;
String words;
public Speech(String words)
{
this.words = words;
}
public void setVoice()
{
try
{
String synthesizerName = System.getProperty("synthesizerName","Unlimited domain FreeTTS Speech Synthesizer from Sun Labs");
SynthesizerModeDesc desc = new SynthesizerModeDesc
(synthesizerName,
null,
Locale.US,
Boolean.FALSE,
null);
synthesizer = Central.createSynthesizer(desc);
if (synthesizer == null)
{
String message = "Can't find synthesizer.\n" +
"Make sure that there is a \"speech.properties\" file " +
"at either of these locations: \n";
message += "user.home : " +
System.getProperty("user.home") + "\n";
message += "java.home/lib: " + System.getProperty("java.home")
+ File.separator + "lib\n";
System.err.println(message);
System.exit(1);
}
String voiceName = System.getProperty("voiceName", "kevin16");
Voice voice = new Voice(voiceName, Voice.GENDER_DONT_CARE, Voice.AGE_DONT_CARE, null);
synthesizer.allocate();
synthesizer.resume();
synthesizer.getSynthesizerProperties().setVoice(voice);
}
catch(Exception e)
{
System.out.println(e);
}
}
public void doSpeak()
{
try
{
// speak the "Hello world" string
synthesizer.speakPlainText(words, null);
// wait till speaking is done
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
// clean up
synthesizer.deallocate();
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String[] argv)
{
String words = "Hello world!";
Speech speech = new Speech(words);
speech.setVoice();
speech.doSpeak();
}
}