/**
 * Copyright 2015 IBM Corp. All Rights Reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.ibm.watson.developer_cloud.text_to_speech.v1;

import java.util.List;

import com.ibm.watson.developer_cloud.text_to_speech.v1.model.CustomTranslation;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.CustomVoiceModel;

public class CustomizationExample {

  public static void main(String[] args) {
    TextToSpeech service = new TextToSpeech();
    service.setUsernameAndPassword("<username>", "<password>");

    //create custom voice model.
    CustomVoiceModel model = new CustomVoiceModel();
    model.setName("my model");
    model.setLanguage("en-us");
    model.setDescription("the model for testing");
    CustomVoiceModel customVoiceModel = service.saveCustomVoiceModel(model).execute();
    System.out.println(customVoiceModel);

    //list custom voice models
    List<CustomVoiceModel> customVoiceModels = service.getCustomVoiceModels("en-us").execute();
    System.out.println(customVoiceModels);

    //create custom word translations
    CustomTranslation customTranslation = new CustomTranslation("hodor", "hold the door");
    service.saveWords(customVoiceModel, customTranslation).execute();

    //get custom word translations
    List<CustomTranslation> words = service.getWords(customVoiceModel).execute();
    System.out.println(words);
  }

}

@@ -685,179 +685,534 @@
 ava.
-util.List;%0A%0Aimport com.ibm.watson.developer_cloud.text_to_speech.v1.model.CustomTranslation;%0Aimport com.ibm.watson.developer_cloud.text_to_speech.v1.model.CustomVoiceModel
+io.File;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.util.List;%0A%0Aimport com.ibm.watson.developer_cloud.text_to_speech.v1.model.AudioFormat;%0Aimport com.ibm.watson.developer_cloud.text_to_speech.v1.model.CustomTranslation;%0Aimport com.ibm.watson.developer_cloud.text_to_speech.v1.model.CustomVoiceModel;%0Aimport com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice;%0Aimport com.ibm.watson.developer_cloud.text_to_speech.v1.util.WaveUtils
 ;%0A%0Ap
@@ -1287,16 +1287,35 @@
 %5B%5D args)
+ throws IOException
  %7B%0A    T
@@ -1357,46 +1357,8 @@
 ech(
-);%0A    service.setUsernameAndPassword(
 %22%3Cus
@@ -1961,16 +1961,17 @@
 nslation
+1
  = new C
@@ -2010,24 +2010,107 @@
 the door%22);%0A
+    CustomTranslation customTranslation2 = new CustomTranslation(%22plz%22, %22please%22);%0A
     service.
@@ -2154,16 +2154,37 @@
 nslation
+1, customTranslation2
 ).execut
@@ -2341,11 +2341,635 @@
 s);%0A
+%0A    //synthesize with custom voice model%0A    String text = %22plz hodor%22;%0A    InputStream in = service.synthesize(text, Voice.EN_MICHAEL, AudioFormat.WAV, customVoiceModel.getId()).execute();%0A    writeToFile(WaveUtils.reWriteWaveHeader(in), new File(%22output.wav%22));%0A  %7D%0A%0A  private static void writeToFile(InputStream in, File file) %7B%0A    try %7B%0A      OutputStream out = new FileOutputStream(file);%0A      byte%5B%5D buf = new byte%5B1024%5D;%0A      int len;%0A      while ((len = in.read(buf)) %3E 0) %7B%0A        out.write(buf, 0, len);%0A      %7D%0A      out.close();%0A      in.close();%0A    %7D catch (Exception e) %7B%0A      e.printStackTrace();%0A    %7D%0A
   %7D
-%0A
 %0A%7D%0A

add speech synthesize with custom voice model.