Search in sources :

Example 1 with ListAudioOptions

use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListAudioOptions 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 2 with ListAudioOptions

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

the class SpeechToText method listAudio.

/**
 * Lists information about all audio resources for a custom acoustic model.
 *
 * Lists information about all audio resources from a custom acoustic model. The information includes the name of the
 * resource and information about its audio data, such as its duration. It also includes the status of the audio
 * resource, which is important for checking the service's analysis of the resource in response to a request to add it
 * to the custom acoustic model. You must use credentials for the instance of the service that owns a model to list
 * its audio resources.
 *
 * @param listAudioOptions the {@link ListAudioOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link AudioResources}
 */
public ServiceCall<AudioResources> listAudio(ListAudioOptions listAudioOptions) {
    Validator.notNull(listAudioOptions, "listAudioOptions cannot be null");
    String[] pathSegments = { "v1/acoustic_customizations", "audio" };
    String[] pathParameters = { listAudioOptions.customizationId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(AudioResources.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) AudioResources(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResources)

Example 3 with ListAudioOptions

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

the class SpeechToTextTest method testListAudio.

@Test
public void testListAudio() throws FileNotFoundException, InterruptedException {
    String resourcesAsString = getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/audio-resources.json"));
    JsonObject audioResources = new JsonParser().parse(resourcesAsString).getAsJsonObject();
    String id = "foo";
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(resourcesAsString));
    ListAudioOptions listOptions = new ListAudioOptions.Builder().customizationId(id).build();
    AudioResources result = service.listAudio(listOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("GET", request.getMethod());
    assertEquals(String.format(PATH_ALL_AUDIO, id), request.getPath());
    assertEquals(audioResources.get("audio").getAsJsonArray().size(), result.getAudio().size());
    assertEquals(audioResources.get("audio"), GSON.toJsonTree(result.getAudio()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) AudioResources(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResources) ListAudioOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListAudioOptions) JsonObject(com.google.gson.JsonObject) ByteString(okio.ByteString) FileInputStream(java.io.FileInputStream) JsonParser(com.google.gson.JsonParser) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

AudioResources (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResources)3 ListAudioOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListAudioOptions)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 AcousticModel (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AcousticModel)1 CreateAcousticModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions)1 DeleteAcousticModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteAcousticModelOptions)1 FileInputStream (java.io.FileInputStream)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 ByteString (okio.ByteString)1