2016-03-26 40 views
0

我使用VOCE庫(https://sourceforge.net/projects/voce/)在Java中進行語音合成,並使用netbeans作爲應用程序,下面是代碼。沒有語音輸出

public class synthesisTest{ 
public static void main(String[] argv){ 

    voce.SpeechInterface.init("../../../lib", true, false, "", ""); 

    voce.SpeechInterface.synthesize("This is a speech synthesis test."); 
    voce.SpeechInterface.synthesize("Type a message to hear it spoken " 
     + "aloud."); 

    try 
    { 
     String s = "Hey testing"; 
     voce.SpeechInterface.synthesize(s); 
     voce.SpeechInterface.stopSynthesizing(); 
    } 
    catch (Exception ioe) 
    { 
     System.out.println("error:" + ioe); 
    } 

    voce.SpeechInterface.destroy(); 
    System.exit(0); 
} 
} 

然而,當我運行這段代碼的輸出是

[Voce] Initializing synthesizer 
[Voce] Initialization complete 
[Voce] Shutdown complete 
BUILD SUCCESSFUL (total time: 0 seconds) 

但無聲音輸出。但是,如果從控制檯讀取字符串,它會給出輸出。如何解決這個問題,因爲我希望這可以用於代碼中提供的字符串?

+0

開始後你可以直接停下來嗎? voce.SpeechInterface.synthesize(一個或多個); voce.SpeechInterface.stopSynthesizing();在這些線之間放置一個睡眠(3000)。 – Tokazio

+0

怎麼樣? voce.SpeechInterface.synthesize(一個或多個); – Subhiksh

+0

在voce文檔中,用於stopSynthetizing():「告訴語音合成器停止合成,取消所有待處理的消息。 」 – Tokazio

回答

1

你叫

voce.SpeechInterface.synthesize(s); 

即開始演講

voce.SpeechInterface.stopSynthesizing(); 

從技術文檔: 「告訴語音合成停止合成這將取消所有待處理的消息。」

然後語音立即停止。

您必須等待演講結束,不要強迫停止演講。 這必須在循環中完成,否則應用程序在演講前結束。