Search in sources :

Example 1 with AcousticModel

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

the class SpeechToTextIT method testCreateAcousticModel.

/**
 * Test create acoustic model.
 */
@Test
public void testCreateAcousticModel() {
    String name = "java-sdk-temporary";
    String description = "Temporary custom model for testing the Java SDK";
    CreateAcousticModelOptions createOptions = new CreateAcousticModelOptions.Builder().name(name).baseModelName(EN_BROADBAND16K).description(description).build();
    AcousticModel myModel = service.createAcousticModel(createOptions).execute();
    String id = myModel.getCustomizationId();
    try {
        GetAcousticModelOptions getOptions = new GetAcousticModelOptions.Builder().customizationId(id).build();
        AcousticModel model = service.getAcousticModel(getOptions).execute();
        assertNotNull(model);
        assertEquals(name, model.getName());
        assertEquals(EN_BROADBAND16K, model.getBaseModelName());
        assertEquals(description, model.getDescription());
    } finally {
        DeleteAcousticModelOptions deleteOptions = new DeleteAcousticModelOptions.Builder().customizationId(id).build();
        service.deleteAcousticModel(deleteOptions).execute();
    }
}
Also used : GetAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetAcousticModelOptions) AcousticModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel) CreateAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions) DeleteAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteAcousticModelOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with AcousticModel

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

the class SpeechToTextIT method testListAudio.

/**
 * Test list audio.
 */
@Test
public void testListAudio() {
    String name = "java-sdk-temporary";
    String description = "Temporary custom model for testing the Java SDK";
    CreateAcousticModelOptions createOptions = new CreateAcousticModelOptions.Builder().name(name).baseModelName(EN_BROADBAND16K).description(description).build();
    AcousticModel myModel = service.createAcousticModel(createOptions).execute();
    String id = myModel.getCustomizationId();
    try {
        ListAudioOptions listOptions = new ListAudioOptions.Builder().customizationId(id).build();
        AudioResources resources = service.listAudio(listOptions).execute();
        assertNotNull(resources);
    } finally {
        DeleteAcousticModelOptions deleteAcousticModelOptions = new DeleteAcousticModelOptions.Builder().customizationId(id).build();
        service.deleteAcousticModel(deleteAcousticModelOptions).execute();
    }
}
Also used : AcousticModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel) CreateAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions) AudioResources(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResources) ListAudioOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListAudioOptions) DeleteAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteAcousticModelOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 3 with AcousticModel

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

the class SpeechToTextIT method testAddAudioArchive.

/**
 * Test add audio with an archive file.
 *
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testAddAudioArchive() throws FileNotFoundException, InterruptedException {
    String name = "java-sdk-temporary";
    String description = "Temporary custom model for testing the Java SDK";
    CreateAcousticModelOptions createOptions = new CreateAcousticModelOptions.Builder().name(name).baseModelName(EN_BROADBAND16K).description(description).build();
    AcousticModel myModel = service.createAcousticModel(createOptions).execute();
    String id = myModel.getCustomizationId();
    String audioName = "test-archive";
    File audio = new File(WAV_ARCHIVE);
    AddAudioOptions addOptions = new AddAudioOptions.Builder().customizationId(id).audioName(audioName).contentType(AddAudioOptions.ContentType.APPLICATION_ZIP).containedContentType(AddAudioOptions.ContainedContentType.AUDIO_WAV).audioResource(audio).build();
    service.addAudio(addOptions).execute();
    try {
        GetAudioOptions getOptions = new GetAudioOptions.Builder().customizationId(id).audioName(audioName).build();
        AudioListing listing = service.getAudio(getOptions).execute();
        assertNotNull(listing);
        assertEquals(audioName, listing.getName());
    } finally {
        DeleteAudioOptions deleteAudioOptions = new DeleteAudioOptions.Builder().customizationId(id).audioName(audioName).build();
        service.deleteAudio(deleteAudioOptions).execute();
        GetAcousticModelOptions getOptions = new GetAcousticModelOptions.Builder().customizationId(id).build();
        for (int x = 0; x < 30 && !service.getAcousticModel(getOptions).execute().getStatus().equals(AcousticModel.Status.AVAILABLE); x++) {
            Thread.sleep(5000);
        }
        DeleteAcousticModelOptions deleteAcousticModelOptions = new DeleteAcousticModelOptions.Builder().customizationId(id).build();
        service.deleteAcousticModel(deleteAcousticModelOptions).execute();
    }
}
Also used : GetAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetAcousticModelOptions) AcousticModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel) AddAudioOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddAudioOptions) CreateAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions) GetAudioOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetAudioOptions) DeleteAudioOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteAudioOptions) DeleteAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteAcousticModelOptions) AudioListing(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioListing) File(java.io.File) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 4 with AcousticModel

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

the class SpeechToTextTest method testGetAcousticModel.

/**
 * Test get acoustic model.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testGetAcousticModel() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    AcousticModel model = loadFixture("src/test/resources/speech_to_text/acoustic-model.json", AcousticModel.class);
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(GSON.toJson(model)));
    GetAcousticModelOptions getOptions = new GetAcousticModelOptions.Builder().customizationId(id).build();
    AcousticModel result = service.getAcousticModel(getOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("GET", request.getMethod());
    assertEquals(String.format(PATH_ACOUSTIC_CUSTOMIZATION, id), request.getPath());
    assertEquals(result.toString(), model.toString());
}
Also used : GetAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetAcousticModelOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AcousticModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel) MockResponse(okhttp3.mockwebserver.MockResponse) ByteString(okio.ByteString) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with AcousticModel

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

the class SpeechToTextTest method testCreateAcousticModel.

/**
 * Test create acoustic model.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testCreateAcousticModel() throws InterruptedException, FileNotFoundException {
    AcousticModel model = loadFixture("src/test/resources/speech_to_text/acoustic-model.json", AcousticModel.class);
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(GSON.toJson(model)));
    CreateAcousticModelOptions createOptions = new CreateAcousticModelOptions.Builder().name(model.getName()).baseModelName(model.getBaseModelName()).description(model.getDescription()).build();
    AcousticModel result = service.createAcousticModel(createOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("POST", request.getMethod());
    assertEquals(PATH_ACOUSTIC_CUSTOMIZATIONS, request.getPath());
    assertEquals(result.toString(), model.toString());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AcousticModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel) MockResponse(okhttp3.mockwebserver.MockResponse) CreateAcousticModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

AcousticModel (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel)8 Test (org.junit.Test)6 CreateAcousticModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 DeleteAcousticModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteAcousticModelOptions)4 GetAcousticModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetAcousticModelOptions)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 AddAudioOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddAudioOptions)2 AudioListing (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioListing)2 DeleteAudioOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteAudioOptions)2 GetAudioOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetAudioOptions)2 File (java.io.File)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 JsonObject (com.google.gson.JsonObject)1 AudioResources (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResources)1 ListAudioOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListAudioOptions)1 ByteString (okio.ByteString)1 Ignore (org.junit.Ignore)1