Search in sources :

Example 1 with PromptMetadata

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

the class TextToSpeechIT method testGetCustomPrompts.

/**
 * Test getCustomPrompts.
 */
@Test
public void testGetCustomPrompts() {
    try {
        CreateCustomModelOptions createCustomModelOptions = new CreateCustomModelOptions.Builder().description("testdescription").name("testname").language(CreateCustomModelOptions.Language.EN_US).build();
        CustomModel customModel = service.createCustomModel(createCustomModelOptions).execute().getResult();
        customizationId = customModel.getCustomizationId();
        PromptMetadata promptMetadata = new PromptMetadata.Builder().promptText("promptText").build();
        File file = new File(RESOURCE + "numbers.wav");
        AddCustomPromptOptions addCustomPromptOptions = new AddCustomPromptOptions.Builder().customizationId(customizationId).promptId("testId").metadata(promptMetadata).file(file).build();
        Prompt prompt = service.addCustomPrompt(addCustomPromptOptions).execute().getResult();
        assertNotNull(prompt.getStatus());
        GetCustomPromptOptions getCustomPromptOptions = new GetCustomPromptOptions.Builder().customizationId(customizationId).promptId("testId").build();
        Prompt prompt1 = service.getCustomPrompt(getCustomPromptOptions).execute().getResult();
        assertNotNull(prompt1.getStatus());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteCustomModelOptions deleteCustomModelOptions = new DeleteCustomModelOptions.Builder().customizationId(customizationId).build();
        service.deleteCustomModel(deleteCustomModelOptions).execute().getResult();
    }
}
Also used : CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) AddCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions) GetCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.GetCustomPromptOptions) PromptMetadata(com.ibm.watson.text_to_speech.v1.model.PromptMetadata) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt) DeleteCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions) File(java.io.File) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 2 with PromptMetadata

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

the class TextToSpeechIT method testAddCustomPrompts.

/**
 * Test addCustomPrompts.
 */
@Test
public void testAddCustomPrompts() {
    try {
        CreateCustomModelOptions createCustomModelOptions = new CreateCustomModelOptions.Builder().description("testdescription").name("testname").language(CreateCustomModelOptions.Language.EN_US).build();
        CustomModel customModel = service.createCustomModel(createCustomModelOptions).execute().getResult();
        customizationId = customModel.getCustomizationId();
        PromptMetadata promptMetadata = new PromptMetadata.Builder().promptText("promptText").build();
        File file = new File(RESOURCE + "numbers.wav");
        AddCustomPromptOptions addCustomPromptOptions = new AddCustomPromptOptions.Builder().customizationId(customizationId).promptId("testId").metadata(promptMetadata).file(file).build();
        Prompt prompt = service.addCustomPrompt(addCustomPromptOptions).execute().getResult();
        assertNotNull(prompt.getStatus());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteCustomModelOptions deleteCustomModelOptions = new DeleteCustomModelOptions.Builder().customizationId(customizationId).build();
        service.deleteCustomModel(deleteCustomModelOptions).execute().getResult();
    }
}
Also used : CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) AddCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions) PromptMetadata(com.ibm.watson.text_to_speech.v1.model.PromptMetadata) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt) DeleteCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions) File(java.io.File) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 3 with PromptMetadata

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

the class TextToSpeechIT method testDeleteCustomPrompts.

/**
 * Test deleteCustomPrompts.
 */
@Test
public void testDeleteCustomPrompts() {
    try {
        CreateCustomModelOptions createCustomModelOptions = new CreateCustomModelOptions.Builder().description("testdescription").name("testname").language(CreateCustomModelOptions.Language.EN_US).build();
        CustomModel customModel = service.createCustomModel(createCustomModelOptions).execute().getResult();
        customizationId = customModel.getCustomizationId();
        PromptMetadata promptMetadata = new PromptMetadata.Builder().promptText("promptText").build();
        File file = new File(RESOURCE + "numbers.wav");
        AddCustomPromptOptions addCustomPromptOptions = new AddCustomPromptOptions.Builder().customizationId(customizationId).promptId("testId").metadata(promptMetadata).file(file).build();
        Prompt prompt = service.addCustomPrompt(addCustomPromptOptions).execute().getResult();
        assertNotNull(prompt.getStatus());
        DeleteCustomPromptOptions deleteCustomPromptOptions = new DeleteCustomPromptOptions.Builder().customizationId(customizationId).promptId(prompt.getPromptId()).build();
        service.deleteCustomPrompt(deleteCustomPromptOptions).execute().getResult();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DeleteCustomModelOptions deleteCustomModelOptions = new DeleteCustomModelOptions.Builder().customizationId(customizationId).build();
        service.deleteCustomModel(deleteCustomModelOptions).execute().getResult();
    }
}
Also used : CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) AddCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions) DeleteCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomPromptOptions) PromptMetadata(com.ibm.watson.text_to_speech.v1.model.PromptMetadata) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt) DeleteCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions) File(java.io.File) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 4 with PromptMetadata

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

the class TextToSpeechTest method testAddCustomPromptWOptions.

// Test the addCustomPrompt operation with a valid options model parameter
@Test
public void testAddCustomPromptWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}";
    String addCustomPromptPath = "/v1/customizations/testString/prompts/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the PromptMetadata model
    PromptMetadata promptMetadataModel = new PromptMetadata.Builder().promptText("testString").speakerId("testString").build();
    // Construct an instance of the AddCustomPromptOptions model
    AddCustomPromptOptions addCustomPromptOptionsModel = new AddCustomPromptOptions.Builder().customizationId("testString").promptId("testString").metadata(promptMetadataModel).file(TestUtilities.createMockStream("This is a mock file.")).build();
    // Invoke addCustomPrompt() with a valid options model and verify the result
    Response<Prompt> response = textToSpeechService.addCustomPrompt(addCustomPromptOptionsModel).execute();
    assertNotNull(response);
    Prompt responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, addCustomPromptPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) AddCustomPromptOptions(com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions) PromptMetadata(com.ibm.watson.text_to_speech.v1.model.PromptMetadata) Prompt(com.ibm.watson.text_to_speech.v1.model.Prompt) Test(org.testng.annotations.Test)

Aggregations

AddCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.AddCustomPromptOptions)4 Prompt (com.ibm.watson.text_to_speech.v1.model.Prompt)4 PromptMetadata (com.ibm.watson.text_to_speech.v1.model.PromptMetadata)4 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)3 CreateCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions)3 CustomModel (com.ibm.watson.text_to_speech.v1.model.CustomModel)3 DeleteCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.DeleteCustomModelOptions)3 File (java.io.File)3 IOException (java.io.IOException)3 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)3 Test (org.junit.Test)3 DeleteCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.DeleteCustomPromptOptions)1 GetCustomPromptOptions (com.ibm.watson.text_to_speech.v1.model.GetCustomPromptOptions)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1