Skip to content

Commit da7d4a7

Browse files
committed
feat(Speech to Text): Add processingMetrics, processingMetricsInterval, and audioMetrics params to RecognizeOptions
1 parent 128559d commit da7d4a7

1 file changed

Lines changed: 117 additions & 56 deletions

File tree

‎speech-to-text/src/main/java/com/ibm/watson/speech_to_text/v1/model/RecognizeOptions.java‎

Lines changed: 117 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import com.google.gson.annotations.SerializedName;
2322
import com.ibm.cloud.sdk.core.service.model.GenericModel;
2423
import com.ibm.cloud.sdk.core.util.Validator;
2524

@@ -30,7 +29,7 @@ public class RecognizeOptions extends GenericModel {
3029

3130
/**
3231
* The identifier of the model that is to be used for the recognition request. See [Languages and
33-
* models](https://cloud.ibm.com/docs/services/speech-to-text/models.html).
32+
* models](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-models#models).
3433
*/
3534
public interface Model {
3635
/** ar-AR_BroadbandModel. */
@@ -114,7 +113,7 @@ public interface ContentType {
114113
String AUDIO_WEBM_CODECS_VORBIS = "audio/webm;codecs=vorbis";
115114
}
116115

117-
private transient InputStream audio;
116+
private InputStream audio;
118117
private String model;
119118
private String languageCustomizationId;
120119
private String acousticCustomizationId;
@@ -131,10 +130,11 @@ public interface ContentType {
131130
private Boolean smartFormatting;
132131
private Boolean speakerLabels;
133132
private String customizationId;
134-
private Boolean interimResults;
135133
private String grammarName;
136134
private Boolean redaction;
137-
@SerializedName("content-type")
135+
private Boolean processingMetrics;
136+
private Float processingMetricsInterval;
137+
private Boolean audioMetrics;
138138
private String contentType;
139139

140140
/**
@@ -158,9 +158,11 @@ public static class Builder {
158158
private Boolean smartFormatting;
159159
private Boolean speakerLabels;
160160
private String customizationId;
161-
private Boolean interimResults;
162161
private String grammarName;
163162
private Boolean redaction;
163+
private Boolean processingMetrics;
164+
private Float processingMetricsInterval;
165+
private Boolean audioMetrics;
164166
private String contentType;
165167

166168
private Builder(RecognizeOptions recognizeOptions) {
@@ -181,9 +183,11 @@ private Builder(RecognizeOptions recognizeOptions) {
181183
this.smartFormatting = recognizeOptions.smartFormatting;
182184
this.speakerLabels = recognizeOptions.speakerLabels;
183185
this.customizationId = recognizeOptions.customizationId;
184-
this.interimResults = recognizeOptions.interimResults;
185186
this.grammarName = recognizeOptions.grammarName;
186187
this.redaction = recognizeOptions.redaction;
188+
this.processingMetrics = recognizeOptions.processingMetrics;
189+
this.processingMetricsInterval = recognizeOptions.processingMetricsInterval;
190+
this.audioMetrics = recognizeOptions.audioMetrics;
187191
this.contentType = recognizeOptions.contentType;
188192
}
189193

@@ -414,19 +418,6 @@ public Builder customizationId(String customizationId) {
414418
return this;
415419
}
416420

417-
/**
418-
* Set the interimResults.
419-
*
420-
* NOTE: This parameter only works for the `recognizeUsingWebSocket` method.
421-
*
422-
* @param interimResults the interimResults
423-
* @return the interimResults
424-
*/
425-
public Builder interimResults(Boolean interimResults) {
426-
this.interimResults = interimResults;
427-
return this;
428-
}
429-
430421
/**
431422
* Set the grammarName.
432423
*
@@ -449,6 +440,39 @@ public Builder redaction(Boolean redaction) {
449440
return this;
450441
}
451442

443+
/**
444+
* Set the processingMetrics.
445+
*
446+
* @param processingMetrics the processingMetrics
447+
* @return the RecognizeOptions builder
448+
*/
449+
public Builder processingMetrics(Boolean processingMetrics) {
450+
this.processingMetrics = processingMetrics;
451+
return this;
452+
}
453+
454+
/**
455+
* Set the processingMetricsInterval.
456+
*
457+
* @param processingMetricsInterval the processingMetricsInterval
458+
* @return the RecognizeOptions builder
459+
*/
460+
public Builder processingMetricsInterval(Float processingMetricsInterval) {
461+
this.processingMetricsInterval = processingMetricsInterval;
462+
return this;
463+
}
464+
465+
/**
466+
* Set the audioMetrics.
467+
*
468+
* @param audioMetrics the audioMetrics
469+
* @return the RecognizeOptions builder
470+
*/
471+
public Builder audioMetrics(Boolean audioMetrics) {
472+
this.audioMetrics = audioMetrics;
473+
return this;
474+
}
475+
452476
/**
453477
* Set the contentType.
454478
*
@@ -493,9 +517,11 @@ private RecognizeOptions(Builder builder) {
493517
smartFormatting = builder.smartFormatting;
494518
speakerLabels = builder.speakerLabels;
495519
customizationId = builder.customizationId;
496-
interimResults = builder.interimResults;
497520
grammarName = builder.grammarName;
498521
redaction = builder.redaction;
522+
processingMetrics = builder.processingMetrics;
523+
processingMetricsInterval = builder.processingMetricsInterval;
524+
audioMetrics = builder.audioMetrics;
499525
contentType = builder.contentType;
500526
}
501527

@@ -523,7 +549,7 @@ public InputStream audio() {
523549
* Gets the model.
524550
*
525551
* The identifier of the model that is to be used for the recognition request. See [Languages and
526-
* models](https://cloud.ibm.com/docs/services/speech-to-text/models.html).
552+
* models](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-models#models).
527553
*
528554
* @return the model
529555
*/
@@ -538,7 +564,7 @@ public String model() {
538564
* model of the specified custom language model must match the model specified with the `model` parameter. You must
539565
* make the request with credentials for the instance of the service that owns the custom model. By default, no custom
540566
* language model is used. See [Custom
541-
* models](https://cloud.ibm.com/docs/services/speech-to-text/input.html#custom-input).
567+
* models](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#custom-input).
542568
*
543569
* **Note:** Use this parameter instead of the deprecated `customization_id` parameter.
544570
*
@@ -555,7 +581,7 @@ public String languageCustomizationId() {
555581
* model of the specified custom acoustic model must match the model specified with the `model` parameter. You must
556582
* make the request with credentials for the instance of the service that owns the custom model. By default, no custom
557583
* acoustic model is used. See [Custom
558-
* models](https://cloud.ibm.com/docs/services/speech-to-text/input.html#custom-input).
584+
* models](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#custom-input).
559585
*
560586
* @return the acousticCustomizationId
561587
*/
@@ -566,11 +592,11 @@ public String acousticCustomizationId() {
566592
/**
567593
* Gets the baseModelVersion.
568594
*
569-
* The version of the specified base model that is to be used with recognition request. Multiple versions of a base
570-
* model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with
571-
* custom models that have been upgraded for a new base model. The default value depends on whether the parameter is
572-
* used with or without a custom model. See [Base model
573-
* version](https://cloud.ibm.com/docs/services/speech-to-text/input.html#version).
595+
* The version of the specified base model that is to be used with the recognition request. Multiple versions of a
596+
* base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use
597+
* with custom models that have been upgraded for a new base model. The default value depends on whether the parameter
598+
* is used with or without a custom model. See [Base model
599+
* version](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#version).
574600
*
575601
* @return the baseModelVersion
576602
*/
@@ -593,7 +619,7 @@ public String baseModelVersion() {
593619
* OOV words from the custom model. Use caution when setting the weight: a higher value can improve the accuracy of
594620
* phrases from the custom model's domain, but it can negatively affect performance on non-domain phrases.
595621
*
596-
* See [Custom models](https://cloud.ibm.com/docs/services/speech-to-text/input.html#custom-input).
622+
* See [Custom models](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#custom-input).
597623
*
598624
* @return the customizationWeight
599625
*/
@@ -607,7 +633,7 @@ public Double customizationWeight() {
607633
* The time in seconds after which, if only silence (no speech) is detected in streaming audio, the connection is
608634
* closed with a 400 error. The parameter is useful for stopping audio submission from a live microphone when a user
609635
* simply walks away. Use `-1` for infinity. See [Inactivity
610-
* timeout](https://cloud.ibm.com/docs/services/speech-to-text/input.html#timeouts-inactivity).
636+
* timeout](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#timeouts-inactivity).
611637
*
612638
* @return the inactivityTimeout
613639
*/
@@ -622,7 +648,7 @@ public Long inactivityTimeout() {
622648
* Keywords are spotted only in the final results, not in interim hypotheses. If you specify any keywords, you must
623649
* also specify a keywords threshold. You can spot a maximum of 1000 keywords. Omit the parameter or specify an empty
624650
* array if you do not need to spot keywords. See [Keyword
625-
* spotting](https://cloud.ibm.com/docs/services/speech-to-text/output.html#keyword_spotting).
651+
* spotting](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#keyword_spotting).
626652
*
627653
* @return the keywords
628654
*/
@@ -636,7 +662,8 @@ public List<String> keywords() {
636662
* A confidence value that is the lower bound for spotting a keyword. A word is considered to match a keyword if its
637663
* confidence is greater than or equal to the threshold. Specify a probability between 0.0 and 1.0. If you specify a
638664
* threshold, you must also specify one or more keywords. The service performs no keyword spotting if you omit either
639-
* parameter. See [Keyword spotting](https://cloud.ibm.com/docs/services/speech-to-text/output.html#keyword_spotting).
665+
* parameter. See [Keyword
666+
* spotting](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#keyword_spotting).
640667
*
641668
* @return the keywordsThreshold
642669
*/
@@ -649,7 +676,7 @@ public Float keywordsThreshold() {
649676
*
650677
* The maximum number of alternative transcripts that the service is to return. By default, the service returns a
651678
* single transcript. If you specify a value of `0`, the service uses the default value, `1`. See [Maximum
652-
* alternatives](https://cloud.ibm.com/docs/services/speech-to-text/output.html#max_alternatives).
679+
* alternatives](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#max_alternatives).
653680
*
654681
* @return the maxAlternatives
655682
*/
@@ -663,7 +690,8 @@ public Long maxAlternatives() {
663690
* A confidence value that is the lower bound for identifying a hypothesis as a possible word alternative (also known
664691
* as "Confusion Networks"). An alternative word is considered if its confidence is greater than or equal to the
665692
* threshold. Specify a probability between 0.0 and 1.0. By default, the service computes no alternative words. See
666-
* [Word alternatives](https://cloud.ibm.com/docs/services/speech-to-text/output.html#word_alternatives).
693+
* [Word
694+
* alternatives](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#word_alternatives).
667695
*
668696
* @return the wordAlternativesThreshold
669697
*/
@@ -676,7 +704,7 @@ public Float wordAlternativesThreshold() {
676704
*
677705
* If `true`, the service returns a confidence measure in the range of 0.0 to 1.0 for each word. By default, the
678706
* service returns no word confidence scores. See [Word
679-
* confidence](https://cloud.ibm.com/docs/services/speech-to-text/output.html#word_confidence).
707+
* confidence](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#word_confidence).
680708
*
681709
* @return the wordConfidence
682710
*/
@@ -688,7 +716,7 @@ public Boolean wordConfidence() {
688716
* Gets the timestamps.
689717
*
690718
* If `true`, the service returns time alignment for each word. By default, no timestamps are returned. See [Word
691-
* timestamps](https://cloud.ibm.com/docs/services/speech-to-text/output.html#word_timestamps).
719+
* timestamps](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#word_timestamps).
692720
*
693721
* @return the timestamps
694722
*/
@@ -702,7 +730,7 @@ public Boolean timestamps() {
702730
* If `true`, the service filters profanity from all output except for keyword results by replacing inappropriate
703731
* words with a series of asterisks. Set the parameter to `false` to return results with no censoring. Applies to US
704732
* English transcription only. See [Profanity
705-
* filtering](https://cloud.ibm.com/docs/services/speech-to-text/output.html#profanity_filter).
733+
* filtering](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#profanity_filter).
706734
*
707735
* @return the profanityFilter
708736
*/
@@ -720,7 +748,8 @@ public Boolean profanityFilter() {
720748
*
721749
* **Note:** Applies to US English, Japanese, and Spanish transcription only.
722750
*
723-
* See [Smart formatting](https://cloud.ibm.com/docs/services/speech-to-text/output.html#smart_formatting).
751+
* See [Smart
752+
* formatting](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#smart_formatting).
724753
*
725754
* @return the smartFormatting
726755
*/
@@ -739,7 +768,8 @@ public Boolean smartFormatting() {
739768
* supports speaker labels, you can also use the **Get a model** method and check that the attribute `speaker_labels`
740769
* is set to `true`.
741770
*
742-
* See [Speaker labels](https://cloud.ibm.com/docs/services/speech-to-text/output.html#speaker_labels).
771+
* See [Speaker
772+
* labels](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#speaker_labels).
743773
*
744774
* @return the speakerLabels
745775
*/
@@ -759,28 +789,14 @@ public String customizationId() {
759789
return customizationId;
760790
}
761791

762-
/**
763-
* Gets the interimResults.
764-
*
765-
* If `true`, the service returns interim results as a stream of `SpeechRecognitionResults` objects. By default,
766-
* the service returns a single `SpeechRecognitionResults` object with final results only.
767-
*
768-
* NOTE: This parameter only works for the `recognizeUsingWebSocket` method.
769-
*
770-
* @return the interimResults
771-
*/
772-
public Boolean interimResults() {
773-
return interimResults;
774-
}
775-
776792
/**
777793
* Gets the grammarName.
778794
*
779795
* The name of a grammar that is to be used with the recognition request. If you specify a grammar, you must also use
780796
* the `language_customization_id` parameter to specify the name of the custom language model for which the grammar is
781797
* defined. The service recognizes only strings that are recognized by the specified grammar; it does not recognize
782798
* other custom words from the model's words resource. See
783-
* [Grammars](https://cloud.ibm.com/docs/services/speech-to-text/input.html#grammars-input).
799+
* [Grammars](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#grammars-input).
784800
*
785801
* @return the grammarName
786802
*/
@@ -802,14 +818,59 @@ public String grammarName() {
802818
*
803819
* **Note:** Applies to US English, Japanese, and Korean transcription only.
804820
*
805-
* See [Numeric redaction](https://cloud.ibm.com/docs/services/speech-to-text/output.html#redaction).
821+
* See [Numeric redaction](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#redaction).
806822
*
807823
* @return the redaction
808824
*/
809825
public Boolean redaction() {
810826
return redaction;
811827
}
812828

829+
/**
830+
* Gets the processingMetrics.
831+
*
832+
* If `true`, requests processing metrics about the service's transcription of the input audio. The service returns
833+
* processing metrics at the interval specified by the `processing_metrics_interval` parameter. It also returns
834+
* processing metrics for transcription events, for example, for final and interim results. By default, the service
835+
* returns no processing metrics.
836+
*
837+
* @return the processingMetrics
838+
*/
839+
public Boolean processingMetrics() {
840+
return processingMetrics;
841+
}
842+
843+
/**
844+
* Gets the processingMetricsInterval.
845+
*
846+
* Specifies the interval in real wall-clock seconds at which the service is to return processing metrics. The
847+
* parameter is ignored unless the `processing_metrics` parameter is set to `true`.
848+
*
849+
* The parameter accepts a minimum value of 0.1 seconds. The level of precision is not restricted, so you can specify
850+
* values such as 0.25 and 0.125.
851+
*
852+
* The service does not impose a maximum value. If you want to receive processing metrics only for transcription
853+
* events instead of at periodic intervals, set the value to a large number. If the value is larger than the duration
854+
* of the audio, the service returns processing metrics only for transcription events.
855+
*
856+
* @return the processingMetricsInterval
857+
*/
858+
public Float processingMetricsInterval() {
859+
return processingMetricsInterval;
860+
}
861+
862+
/**
863+
* Gets the audioMetrics.
864+
*
865+
* If `true`, requests detailed information about the signal characteristics of the input audio. The service returns
866+
* audio metrics with the final transcription results. By default, the service returns no audio metrics.
867+
*
868+
* @return the audioMetrics
869+
*/
870+
public Boolean audioMetrics() {
871+
return audioMetrics;
872+
}
873+
813874
/**
814875
* Gets the contentType.
815876
*

0 commit comments

Comments
 (0)