import javax.speech.*;
import java.util.*;// creates a default Systhesize
import javax.speech.synthesis.*; //code for text-speech engine
public class SpeechUtils
{
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)
{
SpeechUtils obj=new SpeechUtils();
obj.dospeak(args[0],"life is beautiful");//getting an exception here....
}
}
如何解决此异常?我收到一个错误,例如
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at SpeechUtils.main(SpeechUtils.java:44)".
它是一个 Java 程序或文本到语音的转换。我导入了所有必要的库。但无法单独修复此异常