use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class SpeechToText method deleteAcousticModel.
/**
* Deletes a custom acoustic model.
*
* Deletes an existing custom acoustic model. The custom model cannot be deleted if another request, such as adding an
* audio resource to the model, is currently being processed. You must use credentials for the instance of the service
* that owns a model to delete it.
*
* @param deleteAcousticModelOptions the {@link DeleteAcousticModelOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> deleteAcousticModel(DeleteAcousticModelOptions deleteAcousticModelOptions) {
Validator.notNull(deleteAcousticModelOptions, "deleteAcousticModelOptions cannot be null");
String[] pathSegments = { "v1/acoustic_customizations" };
String[] pathParameters = { deleteAcousticModelOptions.customizationId() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class SpeechToText method upgradeAcousticModel.
/**
* Upgrades a custom acoustic model.
*
* Initiates the upgrade of a custom acoustic model to the latest version of its base language model. The upgrade
* method is asynchronous. It can take on the order of minutes or hours to complete depending on the amount of data in
* the custom model and the current load on the service; typically, upgrade takes approximately twice the length of
* the total audio contained in the custom model. A custom model must be in the `ready` or `available` state to be
* upgraded. You must use credentials for the instance of the service that owns a model to upgrade it. The method
* returns an HTTP 200 response code to indicate that the upgrade process has begun successfully. You can monitor the
* status of the upgrade by using the `GET /v1/acoustic_customizations/{customization_id}` method to poll the model's
* status. Use a loop to check the status once a minute. While it is being upgraded, the custom model has the status
* `upgrading`. When the upgrade is complete, the model resumes the status that it had prior to upgrade. The service
* cannot accept subsequent requests for the model until the upgrade completes. If the custom acoustic model was
* trained with a separately created custom language model, you must use the `custom_language_model_id` query
* parameter to specify the GUID of that custom language model. The custom language model must be upgraded before the
* custom acoustic model can be upgraded. Omit the parameter if the custom acoustic model was not trained with a
* custom language model. For more information, see [Upgrading custom
* models](https://console.bluemix.net/docs/services/speech-to-text/custom-upgrade.html).
*
* @param upgradeAcousticModelOptions the {@link UpgradeAcousticModelOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> upgradeAcousticModel(UpgradeAcousticModelOptions upgradeAcousticModelOptions) {
Validator.notNull(upgradeAcousticModelOptions, "upgradeAcousticModelOptions cannot be null");
String[] pathSegments = { "v1/acoustic_customizations", "upgrade_model" };
String[] pathParameters = { upgradeAcousticModelOptions.customizationId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
if (upgradeAcousticModelOptions.customLanguageModelId() != null) {
builder.query("custom_language_model_id", upgradeAcousticModelOptions.customLanguageModelId());
}
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class SpeechToText method addAudio.
/**
* Adds an audio resource to a custom acoustic model.
*
* Adds an audio resource to a custom acoustic model. Add audio content that reflects the acoustic characteristics of
* the audio that you plan to transcribe. You must use credentials for the instance of the service that owns a model
* to add an audio resource to it. Adding audio data does not affect the custom acoustic model until you train the
* model for the new data by using the `POST /v1/acoustic_customizations/{customization_id}/train` method. You can add
* individual audio files or an archive file that contains multiple audio files. Adding multiple audio files via a
* single archive file is significantly more efficient than adding each file individually. * You can add an individual
* audio file in any format that the service supports for speech recognition. Use the `Content-Type` header to specify
* the format of the audio file. * You can add an archive file (**.zip** or **.tar.gz** file) that contains audio
* files in any format that the service supports for speech recognition. All audio files added with the same archive
* file must have the same audio format. Use the `Content-Type` header to specify the archive type, `application/zip`
* or `application/gzip`. Use the `Contained-Content-Type` header to specify the format of the contained audio files;
* the default format is `audio/wav`. You can use this method to add any number of audio resources to a custom model
* by calling the method once for each audio or archive file. But the addition of one audio resource must be fully
* complete before you can add another. You must add a minimum of 10 minutes and a maximum of 50 hours of audio that
* includes speech, not just silence, to a custom acoustic model before you can train it. No audio resource, audio- or
* archive-type, can be larger than 100 MB. The method is asynchronous. It can take several seconds to complete
* depending on the duration of the audio and, in the case of an archive file, the total number of audio files being
* processed. The service returns a 201 response code if the audio is valid. It then asynchronously analyzes the
* contents of the audio file or files and automatically extracts information about the audio such as its length,
* sampling rate, and encoding. You cannot submit requests to add additional audio resources to a custom acoustic
* model, or to train the model, until the service's analysis of all audio files for the current request completes. To
* determine the status of the service's analysis of the audio, use the `GET
* /v1/acoustic_customizations/{customization_id}/audio/{audio_name}` method to poll the status of the audio. The
* method accepts the GUID of the custom model and the name of the audio resource, and it returns the status of the
* resource. Use a loop to check the status of the audio every few seconds until it becomes `ok`. **Note:** The
* sampling rate of an audio file must match the sampling rate of the base model for the custom model: for broadband
* models, at least 16 kHz; for narrowband models, at least 8 kHz. If the sampling rate of the audio is higher than
* the minimum required rate, the service down-samples the audio to the appropriate rate. If the sampling rate of the
* audio is lower than the minimum required rate, the service labels the audio file as `invalid`.
*
* @param addAudioOptions the {@link AddAudioOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> addAudio(AddAudioOptions addAudioOptions) {
Validator.notNull(addAudioOptions, "addAudioOptions cannot be null");
String[] pathSegments = { "v1/acoustic_customizations", "audio" };
String[] pathParameters = { addAudioOptions.customizationId(), addAudioOptions.audioName() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.header("Content-Type", addAudioOptions.contentType());
if (addAudioOptions.containedContentType() != null) {
builder.header("Contained-Content-Type", addAudioOptions.containedContentType());
}
if (addAudioOptions.allowOverwrite() != null) {
builder.query("allow_overwrite", String.valueOf(addAudioOptions.allowOverwrite()));
}
builder.body(InputStreamRequestBody.create(MediaType.parse(addAudioOptions.contentType()), addAudioOptions.audioResource()));
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class SpeechToText method listCorpora.
/**
* Lists information about all corpora for a custom language model.
*
* Lists information about all corpora from a custom language model. The information includes the total number of
* words and out-of-vocabulary (OOV) words, name, and status of each corpus. You must use credentials for the instance
* of the service that owns a model to list its corpora.
*
* @param listCorporaOptions the {@link ListCorporaOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Corpora}
*/
public ServiceCall<Corpora> listCorpora(ListCorporaOptions listCorporaOptions) {
Validator.notNull(listCorporaOptions, "listCorporaOptions cannot be null");
String[] pathSegments = { "v1/customizations", "corpora" };
String[] pathParameters = { listCorporaOptions.customizationId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Corpora.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder 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