use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions 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();
}
}
use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions 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();
}
}
use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions 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.CreateAcousticModelOptions 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());
}
use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateAcousticModelOptions 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));
}
Aggregations