use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResource 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();
}
}
use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResource in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testGetAudio.
@Test
public void testGetAudio() throws InterruptedException, FileNotFoundException {
String id = "foo";
String audioName = "audio1";
AudioResource audio = loadFixture("src/test/resources/speech_to_text/audio-resource.json", AudioResource.class);
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(GSON.toJson(audio)));
GetAudioOptions getOptions = new GetAudioOptions.Builder().customizationId(id).audioName(audioName).build();
AudioListing result = service.getAudio(getOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(String.format(PATH_SPECIFIC_AUDIO, id, audioName), request.getPath());
assertEquals(audio.getDetails(), result.getDetails());
assertEquals(audio.getDuration(), result.getDuration());
assertEquals(audio.getName(), result.getName());
assertEquals(audio.getStatus(), result.getStatus());
}
use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResource in project java-sdk by watson-developer-cloud.
the class SpeechToText method getAudio.
/**
* Lists information about an audio resource for a custom acoustic model.
*
* Lists information about an audio resource from a custom acoustic model. The method returns an `AudioListing` object
* whose fields depend on the type of audio resource you specify with the method's `audio_name` parameter: * **For an
* audio-type resource,** the object's fields match those of an `AudioResource` object: `duration`, `name`, `details`,
* and `status`. * **For an archive-type resource,** the object includes a `container` field whose fields match those
* of an `AudioResource` object. It also includes an `audio` field, which contains an array of `AudioResource` objects
* that provides information about the audio files that are contained in the archive. The information includes the
* status of the specified 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 model. You must use credentials for the instance of the service that
* owns a model to list its audio resources.
*
* @param getAudioOptions the {@link GetAudioOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link AudioListing}
*/
public ServiceCall<AudioListing> getAudio(GetAudioOptions getAudioOptions) {
Validator.notNull(getAudioOptions, "getAudioOptions cannot be null");
String[] pathSegments = { "v1/acoustic_customizations", "audio" };
String[] pathParameters = { getAudioOptions.customizationId(), getAudioOptions.audioName() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(AudioListing.class));
}
use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResource 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();
}
}
use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.AudioResource in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testAddAudio.
@Test
public void testAddAudio() throws InterruptedException, FileNotFoundException {
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
String id = "foo";
String audioName = "test_file";
AddAudioOptions addOptions = new AddAudioOptions.Builder().customizationId(id).audioResource(SAMPLE_WAV).contentType(AddAudioOptions.ContentType.AUDIO_WAV).audioName(audioName).allowOverwrite(true).build();
service.addAudio(addOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals("POST", request.getMethod());
assertEquals(String.format(PATH_SPECIFIC_AUDIO, id, audioName) + "?allow_overwrite=true", request.getPath());
}
Aggregations