Search in sources :

Example 1 with TrainAcousticModelOptions

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

the class SpeechToTextTest method testTrainAcousticModelWOptions.

// Test the trainAcousticModel operation with a valid options model parameter
@Test
public void testTrainAcousticModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"warnings\": [{\"code\": \"invalid_audio_files\", \"message\": \"message\"}]}";
    String trainAcousticModelPath = "/v1/acoustic_customizations/testString/train";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the TrainAcousticModelOptions model
    TrainAcousticModelOptions trainAcousticModelOptionsModel = new TrainAcousticModelOptions.Builder().customizationId("testString").customLanguageModelId("testString").build();
    // Invoke trainAcousticModel() with a valid options model and verify the result
    Response<TrainingResponse> response = speechToTextService.trainAcousticModel(trainAcousticModelOptionsModel).execute();
    assertNotNull(response);
    TrainingResponse 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, trainAcousticModelPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("custom_language_model_id"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) TrainAcousticModelOptions(com.ibm.watson.speech_to_text.v1.model.TrainAcousticModelOptions) TrainingResponse(com.ibm.watson.speech_to_text.v1.model.TrainingResponse) Test(org.testng.annotations.Test)

Example 2 with TrainAcousticModelOptions

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

the class SpeechToTextTest method testTrainAcousticModel.

/**
 * Test train acoustic model.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testTrainAcousticModel() throws InterruptedException, FileNotFoundException {
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    String id = "foo";
    String languageModelId = "bar";
    TrainAcousticModelOptions trainOptions = new TrainAcousticModelOptions.Builder().customizationId(id).customLanguageModelId(languageModelId).build();
    service.trainAcousticModel(trainOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("POST", request.getMethod());
    assertEquals(String.format(PATH_ACOUSTIC_TRAIN, id) + "?custom_language_model_id=bar", request.getPath());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) TrainAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.TrainAcousticModelOptions) ByteString(okio.ByteString) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 TrainAcousticModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.TrainAcousticModelOptions)1 TrainAcousticModelOptions (com.ibm.watson.speech_to_text.v1.model.TrainAcousticModelOptions)1 TrainingResponse (com.ibm.watson.speech_to_text.v1.model.TrainingResponse)1 ByteString (okio.ByteString)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1