Skip to content

Instantly share code, notes, and snippets.

@snippet-java
Last active July 22, 2016 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snippet-java/adc1f3b6acd684f4e6d7d07ae0173ed4 to your computer and use it in GitHub Desktop.
Save snippet-java/adc1f3b6acd684f4e6d7d07ae0173ed4 to your computer and use it in GitHub Desktop.
Text To Speech Snippets
import com.ibm.watson.developer_cloud.text_to_speech.v1.*;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.*;
import java.io.*;import java.util.*;
public class Example {
public static void main(String args[]) {
TextToSpeech service = new TextToSpeech();
service.setEndPoint("https://watson-api-explorer.mybluemix.net/text-to-speech/api"); // SET YOUR URL
//service.setUsernameAndPassword(username,password); // SET YOUR USERNAME AND PASSWORD
}
}
import com.ibm.watson.developer_cloud.text_to_speech.v1.*;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.*;
import java.io.*;import java.util.*;
public class Example {
public static void main(String args[]) {
List<Voice> getVoices()
}
}
import com.ibm.watson.developer_cloud.text_to_speech.v1.*;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.*;
import java.io.*;import java.util.*;
public class Example {
public static void main(String args[]) {
TextToSpeech service = new TextToSpeech();
service.setEndPoint("https://watson-api-explorer.mybluemix.net/text-to-speech/api"); // SET YOUR URL
//service.setUsernameAndPassword(username,password); // SET YOUR USERNAME AND PASSWORD
List<Voice> voices = service.getVoices();
System.out.println(voices);
}
}
import com.ibm.watson.developer_cloud.text_to_speech.v1.*;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.*;
import java.io.*;import java.util.*;
public class Example {
public static void main(String args[]) {
InputStream synthesize(String text, String format)
InputStream synthesize(String text, Voice voice)
InputStream synthesize(String text, Voice voice, String outputFormat)
}
}
import com.ibm.watson.developer_cloud.text_to_speech.v1.*;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.*;
import java.io.*;import java.util.*;
public class Example {
public static void main(String args[]) {
TextToSpeech service = new TextToSpeech();
service.setEndPoint("https://watson-api-explorer.mybluemix.net/text-to-speech/api"); // SET YOUR URL
//service.setUsernameAndPassword(username,password); // SET YOUR USERNAME AND PASSWORD
try {
String text = "Hello world.";
InputStream stream = service.synthesize (text, Voice.EN_ALLISON, "audio/wav");
InputStream in = WaveUtils.reWriteWaveHeader(stream);
OutputStream out = new FileOutputStream("hello_world.wav");
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
out.close();
in.close();
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment