Search in sources :

Example 6 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 SpeechToText method createAcousticModel.

/**
 * Creates a custom acoustic model.
 *
 * Creates a new custom acoustic model for a specified base model. The custom acoustic model can be used only with the
 * base model for which it is created. The model is owned by the instance of the service whose credentials are used to
 * create it.
 *
 * @param createAcousticModelOptions the {@link CreateAcousticModelOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link AcousticModel}
 */
public ServiceCall<AcousticModel> createAcousticModel(CreateAcousticModelOptions createAcousticModelOptions) {
    Validator.notNull(createAcousticModelOptions, "createAcousticModelOptions cannot be null");
    String[] pathSegments = { "v1/acoustic_customizations" };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", createAcousticModelOptions.name());
    contentJson.addProperty("base_model_name", createAcousticModelOptions.baseModelName());
    if (createAcousticModelOptions.description() != null) {
        contentJson.addProperty("description", createAcousticModelOptions.description());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(AcousticModel.class));
}
Also used : AcousticModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject)

Example 7 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 testGetAudio.

/**
 * Test get audio.
 *
 * This test is currently being ignored as it has a very long runtime and causes Travis to timeout.
 * The ignore annotation can be removed to test this locally.
 *
 * @throws InterruptedException the interrupted exception
 */
@Ignore
@Test
public void testGetAudio() throws InterruptedException, FileNotFoundException {
    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 = "sample";
    AddAudioOptions addOptions = new AddAudioOptions.Builder().audioResource(new File(SAMPLE_WAV)).contentType(AddAudioOptions.ContentType.AUDIO_WAV).audioName(audioName).customizationId(id).allowOverwrite(true).build();
    service.addAudio(addOptions).execute();
    try {
        GetAudioOptions getOptions = new GetAudioOptions.Builder().customizationId(id).audioName(audioName).build();
        AudioListing audio = service.getAudio(getOptions).execute();
        assertNotNull(audio);
        assertEquals(audioName, audio.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) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 8 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 SpeechToText method getAcousticModel.

/**
 * Lists information about a custom acoustic model.
 *
 * Lists information about a specified custom acoustic model. You must use credentials for the instance of the service
 * that owns a model to list information about it.
 *
 * @param getAcousticModelOptions the {@link GetAcousticModelOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link AcousticModel}
 */
public ServiceCall<AcousticModel> getAcousticModel(GetAcousticModelOptions getAcousticModelOptions) {
    Validator.notNull(getAcousticModelOptions, "getAcousticModelOptions cannot be null");
    String[] pathSegments = { "v1/acoustic_customizations" };
    String[] pathParameters = { getAcousticModelOptions.customizationId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(AcousticModel.class));
}
Also used : AcousticModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

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