Skip to content

Commit b8b6df3

Browse files
fixes #331 adding profanity_filter
1 parent e449d57 commit b8b6df3

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToText.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ public class SpeechToText extends WatsonService {
7171
private static final String URL = "https://stream.watsonplatform.net/speech-to-text/api";
7272
private static final String WORD_ALTERNATIVES_THRESHOLD = "word_alternatives_threshold";
7373
private static final String WORD_CONFIDENCE = "word_confidence";
74-
74+
private static final String PROFANITY_FILTER = "profanity_filter";
75+
7576
private static final Type TYPE_LIST_MODELS = new TypeToken<List<SpeechModel>>() {}.getType();
7677
private static final Type TYPE_SESSION_STATUS = new TypeToken<SpeechSessionStatus>() {}.getType();
78+
7779

7880
/**
7981
* Instantiates a new Speech to Text service.
@@ -109,6 +111,9 @@ private void buildRecognizeRequest(RequestBuilder requestBuilder, RecognizeOptio
109111
if (options.continuous() != null)
110112
requestBuilder.query(CONTINUOUS, options.continuous());
111113

114+
if (options.profanityFilter() != null)
115+
requestBuilder.query(PROFANITY_FILTER, options.profanityFilter());
116+
112117
if (options.maxAlternatives() != null)
113118
requestBuilder.query(MAX_ALTERNATIVES, options.maxAlternatives());
114119

src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/model/RecognizeOptions.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static class Builder {
4242
private Boolean timestamps;
4343
private Double wordAlternativesThreshold;
4444
private Boolean wordConfidence;
45+
private Boolean profanityFilter;
4546

4647

4748
private Builder(RecognizeOptions options) {
@@ -57,6 +58,7 @@ private Builder(RecognizeOptions options) {
5758
this.timestamps = options.timestamps;
5859
this.wordAlternativesThreshold = options.wordAlternativesThreshold;
5960
this.wordConfidence = options.wordConfidence;
61+
this.profanityFilter = options.profanityFilter;
6062
}
6163

6264
/**
@@ -99,6 +101,19 @@ public Builder contentType(String contentType) {
99101
}
100102

101103

104+
/**
105+
* If true, filters profanity from all output except for keyword results by
106+
* replacing inappropriate words with a series of asterisks. Set the parameter to false to
107+
* return results with no censoring. Applies to US English transcription only.
108+
*
109+
* @param profanityFilter the profanity filter
110+
* @return the recognize options
111+
*/
112+
public Builder profanityFilter(Boolean profanityFilter) {
113+
this.profanityFilter = profanityFilter;
114+
return this;
115+
}
116+
102117
/**
103118
* If true, multiple final results that represent multiple consecutive phrases separated by
104119
* pauses are returned. Otherwise, the recognition ends after first "end of speech" is detected.
@@ -262,7 +277,7 @@ public Builder wordConfidence(Boolean wordConfidence) {
262277
@SerializedName("keywords_threshold")
263278
private Double keywordsThreshold;
264279
private Integer maxAlternatives;
265-
280+
private Boolean profanityFilter;
266281
private String model;
267282
private String sessionId;
268283
private Boolean timestamps;
@@ -284,6 +299,7 @@ private RecognizeOptions(Builder builder) {
284299
this.timestamps = builder.timestamps;
285300
this.wordAlternativesThreshold = builder.wordAlternativesThreshold;
286301
this.wordConfidence = builder.wordConfidence;
302+
this.profanityFilter = builder.profanityFilter;
287303
}
288304

289305
/**
@@ -295,7 +311,15 @@ public String contentType() {
295311
return contentType;
296312
}
297313

298-
314+
/**
315+
* Gets the profanity filter
316+
*
317+
* @return the profanity filter
318+
*/
319+
public Boolean profanityFilter() {
320+
return profanityFilter;
321+
}
322+
299323
/**
300324
* Gets the continuous.
301325
*

src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public void testRecognizeFileStringRecognizeOptions() {
166166
.wordConfidence(true)
167167
.model(EN_BROADBAND16K)
168168
.contentType(contentType)
169+
.profanityFilter(false)
169170
.build();
170171
SpeechResults results = service.recognize(audio, options).execute();
171172
assertNotNull(results.getResults().get(0).getAlternatives().get(0).getTranscript());

0 commit comments

Comments
 (0)