Search in sources :

Example 1 with Word

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word in project java-sdk by watson-developer-cloud.

the class SpeechToTextIT method testGetWord.

/**
 * Test get word.
 */
public void testGetWord() {
    GetWordOptions getOptions = new GetWordOptions.Builder().customizationId(customizationId).wordName("string").build();
    Word result = service.getWord(getOptions).execute();
    assertNotNull(result);
}
Also used : Word(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word) GetWordOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetWordOptions)

Example 2 with Word

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testAddWord.

/**
 * Test add word.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testAddWord() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    Word newWord = loadFixture("src/test/resources/speech_to_text/word.json", Word.class);
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    AddWordOptions addOptions = new AddWordOptions.Builder().wordName(newWord.getWord()).customizationId(id).word(newWord.getWord()).displayAs(newWord.getDisplayAs()).soundsLike(newWord.getSoundsLike()).build();
    service.addWord(addOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("PUT", request.getMethod());
    assertEquals(String.format(PATH_WORD, id, newWord.getWord()), request.getPath());
    assertEquals(GSON.toJson(newWord), request.getBody().readUtf8());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) AddWordOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordOptions) CustomWord(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord) Word(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word) ByteString(okio.ByteString) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 3 with Word

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testGetWord.

/**
 * Test get word.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testGetWord() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    String wordName = "bar";
    String wordAsStr = getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/word.json"));
    JsonObject word = new JsonParser().parse(wordAsStr).getAsJsonObject();
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(wordAsStr));
    GetWordOptions getOptions = new GetWordOptions.Builder().customizationId(id).wordName(wordName).build();
    Word result = service.getWord(getOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("GET", request.getMethod());
    assertEquals(String.format(PATH_WORD, id, wordName), request.getPath());
    assertEquals(word, GSON.toJsonTree(result));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CustomWord(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord) Word(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word) JsonObject(com.google.gson.JsonObject) ByteString(okio.ByteString) GetWordOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetWordOptions) FileInputStream(java.io.FileInputStream) JsonParser(com.google.gson.JsonParser) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 4 with Word

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testAddWords.

/**
 * Test add words.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testAddWords() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    Word newWord = loadFixture("src/test/resources/speech_to_text/word.json", Word.class);
    Map<String, Object> wordsAsMap = new HashMap<String, Object>();
    wordsAsMap.put("words", new Word[] { newWord });
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    CustomWord word = new CustomWord();
    word.setWord(newWord.getWord());
    word.setDisplayAs(newWord.getDisplayAs());
    word.setSoundsLike(newWord.getSoundsLike());
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(id).addWords(word).build();
    service.addWords(addOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("POST", request.getMethod());
    assertEquals(String.format(PATH_WORDS, id), request.getPath());
    assertEquals(GSON.toJson(wordsAsMap), request.getBody().readUtf8());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CustomWord(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord) Word(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordsOptions) HashMap(java.util.HashMap) CustomWord(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord) JsonObject(com.google.gson.JsonObject) ByteString(okio.ByteString) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with Word

use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word in project java-sdk by watson-developer-cloud.

the class CustomizationsIT method testAddWordsJapanese.

/**
 * Test add words and list words for Japanese.
 */
@Test
public void testAddWordsJapanese() {
    model = createVoiceModelJapanese();
    final List<Word> expected = instantiateWordsJapanese();
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(model.getCustomizationId()).words(expected).build();
    service.addWords(addOptions).execute();
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(model.getCustomizationId()).build();
    final Words words = service.listWords(listOptions).execute();
    assertEquals(expected.size(), words.getWords().size());
}
Also used : Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions) Words(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words) ListWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Word (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)16 Test (org.junit.Test)16 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)8 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 AddWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions)6 ListWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions)6 Words (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 Word (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word)5 AddWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordOptions)5 Translation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation)5 GetWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetWordOptions)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 CustomWord (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord)3 DeleteWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.DeleteWordOptions)3 ByteString (okio.ByteString)3 JsonObject (com.google.gson.JsonObject)2 GetWordOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetWordOptions)2 Pronunciation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Pronunciation)2