Skip to content

Commit

Permalink
feat(stt): new params
Browse files Browse the repository at this point in the history
New param list: smartFormattingVersion, force, mappingOnly
  • Loading branch information
apaparazzi0329 committed Feb 26, 2024
1 parent fb139e7 commit 56755c6
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016, 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -12,7 +12,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 3.64.1-cee95189-20230124-211647
* IBM OpenAPI SDK Code Generator Version: 3.85.0-75c38f8f-20240206-210220
*/

package com.ibm.watson.speech_to_text.v1;
Expand Down Expand Up @@ -482,6 +482,10 @@ public ServiceCall<SpeechRecognitionResults> recognize(RecognizeOptions recogniz
if (recognizeOptions.smartFormatting() != null) {
builder.query("smart_formatting", String.valueOf(recognizeOptions.smartFormatting()));
}
if (recognizeOptions.smartFormattingVersion() != null) {
builder.query(
"smart_formatting_version", String.valueOf(recognizeOptions.smartFormattingVersion()));
}
if (recognizeOptions.speakerLabels() != null) {
builder.query("speaker_labels", String.valueOf(recognizeOptions.speakerLabels()));
}
Expand Down Expand Up @@ -798,6 +802,10 @@ public ServiceCall<RecognitionJob> createJob(CreateJobOptions createJobOptions)
if (createJobOptions.smartFormatting() != null) {
builder.query("smart_formatting", String.valueOf(createJobOptions.smartFormatting()));
}
if (createJobOptions.smartFormattingVersion() != null) {
builder.query(
"smart_formatting_version", String.valueOf(createJobOptions.smartFormattingVersion()));
}
if (createJobOptions.speakerLabels() != null) {
builder.query("speaker_labels", String.valueOf(createJobOptions.speakerLabels()));
}
Expand Down Expand Up @@ -1184,10 +1192,16 @@ public ServiceCall<Void> deleteLanguageModel(
* cannot accept subsequent training requests or requests to add new resources until the existing
* request completes.
*
* <p>**See also:** * [Train the custom language
* <p>For custom models that are based on improved base language models, training also performs an
* automatic upgrade to a newer version of the base model. You do not need to use the [Upgrade a
* custom language model](#upgradelanguagemodel) method to perform the upgrade.
*
* <p>**See also:** * [Language support for
* customization](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-support) *
* [Train the custom language
* model](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-languageCreate#trainModel-language)
* * [Language support for
* customization](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-support)
* * [Upgrading custom language models that are based on improved next-generation
* models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-upgrade#custom-upgrade-language-ng)
*
* <p>### Training failures
*
Expand Down Expand Up @@ -1229,6 +1243,9 @@ public ServiceCall<TrainingResponse> trainLanguageModel(
if (trainLanguageModelOptions.strict() != null) {
builder.query("strict", String.valueOf(trainLanguageModelOptions.strict()));
}
if (trainLanguageModelOptions.force() != null) {
builder.query("force", String.valueOf(trainLanguageModelOptions.force()));
}
ResponseConverter<TrainingResponse> responseConverter =
ResponseConverterUtils.getValue(
new com.google.gson.reflect.TypeToken<TrainingResponse>() {}.getType());
Expand Down Expand Up @@ -1291,10 +1308,16 @@ public ServiceCall<Void> resetLanguageModel(ResetLanguageModelOptions resetLangu
* 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.
*
* <p>**See also:** * [Upgrading a custom language
* <p>For custom models that are based on improved base language models, the [Train a custom
* language model](#trainlanguagemodel) method also performs an automatic upgrade to a newer
* version of the base model. You do not need to use the upgrade method.
*
* <p>**See also:** * [Language support for
* customization](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-support) *
* [Upgrading a custom language
* model](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-upgrade#custom-upgrade-language)
* * [Language support for
* customization](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-support).
* * [Upgrading custom language models that are based on improved next-generation
* models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-upgrade#custom-upgrade-language-ng).
*
* @param upgradeLanguageModelOptions the {@link UpgradeLanguageModelOptions} containing the
* options for the call
Expand Down Expand Up @@ -1436,10 +1459,10 @@ public ServiceCall<Void> addCorpus(AddCorpusOptions addCorpusOptions) {
if (addCorpusOptions.allowOverwrite() != null) {
builder.query("allow_overwrite", String.valueOf(addCorpusOptions.allowOverwrite()));
}

// hand edit replacement for corpus file serialization
builder.body(RequestUtils.inputStreamBody(addCorpusOptions.corpusFile(), "text/plain"));

ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
return createServiceCall(builder.build(), responseConverter);
}
Expand Down Expand Up @@ -1601,7 +1624,13 @@ public ServiceCall<Words> listWords(ListWordsOptions listWordsOptions) {
* custom model that is based on a previous-generation model_, if you omit the `sounds_like`
* field, the service attempts to set the field to its pronunciation of the word. It cannot
* generate a pronunciation for all words, so you must review the word's definition to ensure that
* it is complete and valid.
* it is complete and valid. * The `mapping_only` field provides parameter for custom words. You
* can use the 'mapping_only' key in custom words as a form of post processing. This key parameter
* has a boolean value to determine whether 'sounds_like' (for non-Japanese models) or word (for
* Japanese) is not used for the model fine-tuning, but for the replacement for 'display_as'. This
* feature helps you when you use custom words exclusively to map 'sounds_like' (or word) to
* 'display_as' value. When you use custom words solely for post-processing purposes that does not
* need fine-tuning.
*
* <p>If you add a custom word that already exists in the words resource for the custom model, the
* new definition overwrites the existing data for the word. If the service encounters an error
Expand Down Expand Up @@ -1733,6 +1762,12 @@ public ServiceCall<Void> addWord(AddWordOptions addWordOptions) {
if (addWordOptions.word() != null) {
contentJson.addProperty("word", addWordOptions.word());
}
if (addWordOptions.mappingOnly() != null) {
contentJson.add(
"mapping_only",
com.ibm.cloud.sdk.core.util.GsonSingleton.getGson()
.toJsonTree(addWordOptions.mappingOnly()));
}
if (addWordOptions.soundsLike() != null) {
contentJson.add(
"sounds_like",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2018, 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -22,6 +22,7 @@ public class AddWordOptions extends GenericModel {
protected String customizationId;
protected String wordName;
protected String word;
protected List<String> mappingOnly;
protected List<String> soundsLike;
protected String displayAs;

Expand All @@ -30,6 +31,7 @@ public static class Builder {
private String customizationId;
private String wordName;
private String word;
private List<String> mappingOnly;
private List<String> soundsLike;
private String displayAs;

Expand All @@ -42,6 +44,7 @@ private Builder(AddWordOptions addWordOptions) {
this.customizationId = addWordOptions.customizationId;
this.wordName = addWordOptions.wordName;
this.word = addWordOptions.word;
this.mappingOnly = addWordOptions.mappingOnly;
this.soundsLike = addWordOptions.soundsLike;
this.displayAs = addWordOptions.displayAs;
}
Expand Down Expand Up @@ -70,9 +73,24 @@ public AddWordOptions build() {
}

/**
* Adds an soundsLike to soundsLike.
* Adds a new element to mappingOnly.
*
* @param soundsLike the new soundsLike
* @param mappingOnly the new element to be added
* @return the AddWordOptions builder
*/
public Builder addMappingOnly(String mappingOnly) {
com.ibm.cloud.sdk.core.util.Validator.notNull(mappingOnly, "mappingOnly cannot be null");
if (this.mappingOnly == null) {
this.mappingOnly = new ArrayList<String>();
}
this.mappingOnly.add(mappingOnly);
return this;
}

/**
* Adds a new element to soundsLike.
*
* @param soundsLike the new element to be added
* @return the AddWordOptions builder
*/
public Builder addSoundsLike(String soundsLike) {
Expand Down Expand Up @@ -117,6 +135,17 @@ public Builder word(String word) {
return this;
}

/**
* Set the mappingOnly. Existing mappingOnly will be replaced.
*
* @param mappingOnly the mappingOnly
* @return the AddWordOptions builder
*/
public Builder mappingOnly(List<String> mappingOnly) {
this.mappingOnly = mappingOnly;
return this;
}

/**
* Set the soundsLike. Existing soundsLike will be replaced.
*
Expand Down Expand Up @@ -149,6 +178,7 @@ protected AddWordOptions(Builder builder) {
customizationId = builder.customizationId;
wordName = builder.wordName;
word = builder.word;
mappingOnly = builder.mappingOnly;
soundsLike = builder.soundsLike;
displayAs = builder.displayAs;
}
Expand Down Expand Up @@ -178,10 +208,11 @@ public String customizationId() {
/**
* Gets the wordName.
*
* <p>The custom word that is to be added to or updated in the custom language model. Do not
* include spaces in the word. Use a `-` (dash) or `_` (underscore) to connect the tokens of
* compound words. URL-encode the word if it includes non-ASCII characters. For more information,
* see [Character
* <p>The custom word that is to be added to or updated in the custom language model. Do not use
* characters that need to be URL-encoded, for example, spaces, slashes, backslashes, colons,
* ampersands, double quotes, plus signs, equals signs, or question marks. Use a `-` (dash) or `_`
* (underscore) to connect the tokens of compound words. URL-encode the word if it includes
* non-ASCII characters. For more information, see [Character
* encoding](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-corporaWords#charEncoding).
*
* @return the wordName
Expand All @@ -194,8 +225,11 @@ public String wordName() {
* Gets the word.
*
* <p>For the [Add custom words](#addwords) method, you must specify the custom word that is to be
* added to or updated in the custom model. Do not include spaces in the word. Use a `-` (dash) or
* `_` (underscore) to connect the tokens of compound words.
* added to or updated in the custom model. Do not use characters that need to be URL-encoded, for
* example, spaces, slashes, backslashes, colons, ampersands, double quotes, plus signs, equals
* signs, or question marks. Use a `-` (dash) or `_` (underscore) to connect the tokens of
* compound words. A Japanese custom word can include at most 25 characters, not including leading
* or trailing spaces.
*
* <p>Omit this parameter for the [Add a custom word](#addword) method.
*
Expand All @@ -205,6 +239,22 @@ public String word() {
return word;
}

/**
* Gets the mappingOnly.
*
* <p>Parameter for custom words. You can use the 'mapping_only' key in custom words as a form of
* post processing. This key parameter has a boolean value to determine whether 'sounds_like' (for
* non-Japanese models) or word (for Japanese) is not used for the model fine-tuning, but for the
* replacement for 'display_as'. This feature helps you when you use custom words exclusively to
* map 'sounds_like' (or word) to 'display_as' value. When you use custom words solely for
* post-processing purposes that does not need fine-tuning.
*
* @return the mappingOnly
*/
public List<String> mappingOnly() {
return mappingOnly;
}

/**
* Gets the soundsLike.
*
Expand All @@ -218,7 +268,8 @@ public String word() {
* vocabulary.
*
* <p>A word can have at most five sounds-like pronunciations. A pronunciation can include at most
* 40 characters not including spaces.
* 40 characters, not including leading or trailing spaces. A Japanese pronunciation can include
* at most 25 characters, not including leading or trailing spaces.
*
* @return the soundsLike
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2018, 2023.
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -229,6 +229,7 @@ public interface Events {
protected Boolean timestamps;
protected Boolean profanityFilter;
protected Boolean smartFormatting;
protected Boolean smartFormattingVersion;
protected Boolean speakerLabels;
protected String grammarName;
protected Boolean redaction;
Expand Down Expand Up @@ -264,6 +265,7 @@ public static class Builder {
private Boolean timestamps;
private Boolean profanityFilter;
private Boolean smartFormatting;
private Boolean smartFormattingVersion;
private Boolean speakerLabels;
private String grammarName;
private Boolean redaction;
Expand Down Expand Up @@ -303,6 +305,7 @@ private Builder(CreateJobOptions createJobOptions) {
this.timestamps = createJobOptions.timestamps;
this.profanityFilter = createJobOptions.profanityFilter;
this.smartFormatting = createJobOptions.smartFormatting;
this.smartFormattingVersion = createJobOptions.smartFormattingVersion;
this.speakerLabels = createJobOptions.speakerLabels;
this.grammarName = createJobOptions.grammarName;
this.redaction = createJobOptions.redaction;
Expand Down Expand Up @@ -339,9 +342,9 @@ public CreateJobOptions build() {
}

/**
* Adds an keyword to keywords.
* Adds a new element to keywords.
*
* @param keyword the new keyword
* @param keyword the new element to be added
* @return the CreateJobOptions builder
*/
public Builder addKeyword(String keyword) {
Expand Down Expand Up @@ -573,6 +576,17 @@ public Builder smartFormatting(Boolean smartFormatting) {
return this;
}

/**
* Set the smartFormattingVersion.
*
* @param smartFormattingVersion the smartFormattingVersion
* @return the CreateJobOptions builder
*/
public Builder smartFormattingVersion(Boolean smartFormattingVersion) {
this.smartFormattingVersion = smartFormattingVersion;
return this;
}

/**
* Set the speakerLabels.
*
Expand Down Expand Up @@ -742,6 +756,7 @@ protected CreateJobOptions(Builder builder) {
timestamps = builder.timestamps;
profanityFilter = builder.profanityFilter;
smartFormatting = builder.smartFormatting;
smartFormattingVersion = builder.smartFormattingVersion;
speakerLabels = builder.speakerLabels;
grammarName = builder.grammarName;
redaction = builder.redaction;
Expand Down Expand Up @@ -1099,6 +1114,18 @@ public Boolean smartFormatting() {
return smartFormatting;
}

/**
* Gets the smartFormattingVersion.
*
* <p>Smart formatting version is for next-generation models and that is supported in US English,
* Brazilian Portuguese, French and German languages.
*
* @return the smartFormattingVersion
*/
public Boolean smartFormattingVersion() {
return smartFormattingVersion;
}

/**
* Gets the speakerLabels.
*
Expand Down

0 comments on commit 56755c6

Please sign in to comment.