3

我不明白这个语法错误,insert ")" to complete MethodInvocation Syntax error, insert ";" to complete Statement at demojsapi.main(demojsapi.java:46)

我实际上正在使用以下代码将文本转换为 speesh 的 java 项目:

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");
    }
}
4

3 回答 3

5

despeak方法不存在。您应该dospeak改为使用常规引号调用:

obj.dospeak("foo", "kevin16");
于 2012-12-02T16:01:35.430 回答
5

请从给定的链接从谷歌下载 freetts-1.2.2-bin 和

http://sourceforge.net/projects/freetts/?source=directory

在 net beans 中尝试我的程序

不要忘记将所有 jar 文件添加到您的库文件夹中,代码如下所示。它的工作..我的方法---

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){}
} 

从您的内部代码中调用此方法..

于 2015-08-09T20:22:29.350 回答
1

很好地解释了运行代码的完整过程 - 使用 Freetts 在 Java 中的文本到语音

工作代码:

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");    
}    
}
于 2013-10-21T17:10:24.610 回答