use of com.ibm.watson.text_to_speech.v1.model.Voice in project java-sdk by watson-developer-cloud.
the class TextToSpeech method getVoice.
/**
* Retrieves a specific voice available for speech synthesis.
*
* Lists information about the voice specified with the `voice` path parameter. Specify the `customization_id` query
* parameter to obtain information for that custom voice model of the specified voice. Use the `GET /v1/voices` method
* to see a list of all available voices.
*
* @param getVoiceOptions the {@link GetVoiceOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Voice}
*/
public ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions) {
Validator.notNull(getVoiceOptions, "getVoiceOptions cannot be null");
String[] pathSegments = { "v1/voices" };
String[] pathParameters = { getVoiceOptions.voice() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
if (getVoiceOptions.customizationId() != null) {
builder.query("customization_id", getVoiceOptions.customizationId());
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Voice.class));
}
use of com.ibm.watson.text_to_speech.v1.model.Voice in project java-sdk by watson-developer-cloud.
the class CustomizationsTest method testGetVoiceCustomization.
/**
* Test get voice with custom voice model.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testGetVoiceCustomization() throws InterruptedException {
server.enqueue(jsonResponse(voice));
GetVoiceOptions getOptions = new GetVoiceOptions.Builder().voice("en-US_TestMaleVoice").customizationId("cafebabe-1234-5678-9abc-def012345678").build();
final Voice result = service.getVoice(getOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals(VOICES_PATH + "/en-US_TestMaleVoice?customization_id=" + CUSTOMIZATION_ID, request.getPath());
assertEquals("GET", request.getMethod());
assertEquals(voice, result);
}
use of com.ibm.watson.text_to_speech.v1.model.Voice in project java-sdk by watson-developer-cloud.
the class CustomizationExample method main.
public static void main(String[] args) throws IOException {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
TextToSpeech service = new TextToSpeech(authenticator);
// create custom voice model.
CreateCustomModelOptions createOptions = new CreateCustomModelOptions.Builder().name("my model").language("en-US").description("the model for testing").build();
CustomModel customVoiceModel = service.createCustomModel(createOptions).execute().getResult();
System.out.println(customVoiceModel);
// list custom voice models for US English.
ListCustomModelsOptions listOptions = new ListCustomModelsOptions.Builder().language("en-US").build();
CustomModels customVoiceModels = service.listCustomModels(listOptions).execute().getResult();
System.out.println(customVoiceModels);
// update custom voice model.
String newName = "my updated model";
UpdateCustomModelOptions updateOptions = new UpdateCustomModelOptions.Builder().customizationId(customVoiceModel.getCustomizationId()).name(newName).description("the updated model for testing").build();
service.updateCustomModel(updateOptions).execute();
// list custom voice models regardless of language.
customVoiceModels = service.listCustomModels().execute().getResult();
System.out.println(customVoiceModels);
// create multiple custom word translations
Word word1 = new Word.Builder().word("hodor").translation("hold the door").build();
Word word2 = new Word.Builder().word("plz").translation("please").build();
List<Word> words = Arrays.asList(word1, word2);
AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(customVoiceModel.getCustomizationId()).words(words).build();
service.addWords(addOptions).execute();
// create a single custom word translation
AddWordOptions addWordOptions = new AddWordOptions.Builder().word("nat").translation("and that").customizationId(customVoiceModel.getCustomizationId()).build();
service.addWord(addWordOptions).execute();
// get custom word translations
ListWordsOptions listWordsOptions = new ListWordsOptions.Builder().customizationId(customVoiceModel.getCustomizationId()).build();
Words customWords = service.listWords(listWordsOptions).execute().getResult();
System.out.println(customWords);
// get custom word translation
GetWordOptions getOptions = new GetWordOptions.Builder().customizationId(customVoiceModel.getCustomizationId()).word("hodor").build();
Translation translation = service.getWord(getOptions).execute().getResult();
System.out.println(translation);
// synthesize with custom voice model
String text = "plz hodor";
SynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder().text(text).voice(SynthesizeOptions.Voice.EN_US_MICHAELVOICE).accept(HttpMediaType.AUDIO_WAV).customizationId(customVoiceModel.getCustomizationId()).build();
InputStream in = service.synthesize(synthesizeOptions).execute().getResult();
writeToFile(WaveUtils.reWriteWaveHeader(in), new File("output.wav"));
// delete custom words with object and string
DeleteWordOptions deleteOptions1 = new DeleteWordOptions.Builder().customizationId(customVoiceModel.getCustomizationId()).word(word1.word()).build();
service.deleteWord(deleteOptions1).execute();
DeleteWordOptions deleteOptions2 = new DeleteWordOptions.Builder().customizationId(customVoiceModel.getCustomizationId()).word(word2.word()).build();
service.deleteWord(deleteOptions2).execute();
// delete custom voice model
DeleteCustomModelOptions deleteOptions = new DeleteCustomModelOptions.Builder().customizationId(customVoiceModel.getCustomizationId()).build();
service.deleteCustomModel(deleteOptions).execute();
// list custom voice models regardless of language.
customVoiceModels = service.listCustomModels().execute().getResult();
System.out.println(customVoiceModels);
}
use of com.ibm.watson.text_to_speech.v1.model.Voice in project java-sdk by watson-developer-cloud.
the class TextToSpeechIT method testGetVoice.
/**
* Test get voice.
*/
@Test
public void testGetVoice() {
GetVoiceOptions getOptions = new GetVoiceOptions.Builder().voice(voiceName).build();
Voice voice = service.getVoice(getOptions).execute().getResult();
assertNotNull(voice);
assertNotNull(voice.getDescription());
assertNotNull(voice.getGender());
assertNotNull(voice.getLanguage());
assertNotNull(voice.getName());
assertNotNull(voice.getUrl());
}
use of com.ibm.watson.text_to_speech.v1.model.Voice in project java-sdk by watson-developer-cloud.
the class TextToSpeechIT method testSynthesizeAndFixHeader.
/**
* Test the fix wave header not having the size due to be streamed.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws UnsupportedAudioFileException the unsupported audio file exception
*/
@Test
public void testSynthesizeAndFixHeader() throws IOException, UnsupportedAudioFileException {
String text = "one two three four five";
SynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder().text(text).voice(SynthesizeOptions.Voice.EN_US_LISAVOICE).accept(HttpMediaType.AUDIO_WAV).build();
InputStream result = service.synthesize(synthesizeOptions).execute().getResult();
assertNotNull(result);
result = WaveUtils.reWriteWaveHeader(result);
File tempFile = File.createTempFile("output", ".wav");
writeInputStreamToFile(result, tempFile);
assertNotNull(AudioSystem.getAudioFileFormat(tempFile));
}
Aggregations