2017-12-13 12 views
0

のためのオーディオを取得していないのですこれは私のJavaコードです:私はワトソンTTS

import java.io.File; 
    import java.io.FileOutputStream; 
    import java.io.IOException; 
    import java.io.InputStream; 
    import java.io.OutputStream; 

    import com.ibm.watson.developer_cloud.text_to_speech.v1.TextToSpeech; 
    import com.ibm.watson.developer_cloud.text_to_speech.v1.model.AudioFormat; 
    import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice; 

    public static void main(String[] args) { 

    TextToSpeech textService = new TextToSpeech(IBM_WATSON_USERNAME, IBM_WATSON_PASSWORD); 
    String text = "Show me the meaning of being lonely"; 

    try { 
     InputStream in = textService.synthesize(text, Voice.EN_ALLISON, AudioFormat.WAV) 
       .execute(); 
     System.out.println(in.available()); 
     byte[] buffer = new byte[in.available()]; 
     in.read(buffer); 

     File targetFile = new File("local_path/Aud.wav"); 
     OutputStream outStream = new FileOutputStream(targetFile); 
     outStream.write(buffer); 
     outStream.close(); 

    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    } 

私はとEclipseのコンソールでの応答を取得していたコードを実行すると:

Dec 13, 2017 5:38:35 PM okhttp3.internal.platform.Platform log 
INFO: --> POST https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_AllisonVoice&accept=audio/wav http/1.1 (71-byte body) 
Dec 13, 2017 5:38:35 PM okhttp3.internal.platform.Platform log 
INFO: <-- 200 OK https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_AllisonVoice&accept=audio/wav (501ms, unknown-length body) 

値をin.available()のは0です
私はオーディオが生成されていません。コードフローごとに、私は生成された0kBの.wavファイルを取得しています。私は何のオーディオをもらっていませんか?

答えて

2

この単純な方法

public class tts 
{ 
    public static void main(String[] args) throws Exception 
    { 
     TextToSpeech service = new TextToSpeech(); 
     service.setUsernameAndPassword(); 

     String text = "Show me the meaning of being lonely";  
     InputStream stream =service.synthesize(text, Voice.EN_ALLISON, AudioFormat.WAV).execute(); 
      AudioPlayer.player.start(WaveUtils.reWriteWaveHeader(stream)); 
     }} 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
+0

おかげレオナルドをお試しください – Rohit

関連する問題