GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [speech-to-text] Added method to create audio/l16 content type with a · einsnull/java-sdk@3a11f3f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • main/java/com/ibm/watson/developer_cloud
      • http
        • HttpMediaType.java
      • speech_to_text/v1
        • RecognizeOptions.java
    • test/java/com/ibm/watson/developer_cloud/speech_to_text/v1
      • SpeechToTextTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/com/ibm/watson/developer_cloud/http/HttpMediaType.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/ibm/watson/developer_cloud/http/HttpMediaType.java
+51-28Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
*/
1414
package com.ibm.watson.developer_cloud.http;
1515

16+
import java.io.InputStream;
17+
18+
import com.ibm.watson.developer_cloud.speech_to_text.v1.RecognizeOptions;
19+
import com.ibm.watson.developer_cloud.speech_to_text.v1.SpeechToText;
20+
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.RecognizeCallback;
21+
1622
import okhttp3.MediaType;
1723

1824
/**
@@ -21,124 +27,141 @@
2127
* @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7">HTTP/1.1 section
2228
* 3.7</a>
2329
*/
24-
public interface HttpMediaType {
30+
public class HttpMediaType {
31+
32+
private HttpMediaType() {
33+
34+
}
2535

2636
/**
2737
* Field APPLICATION_ATOM_XML. (value is "application/atom+xml")
2838
*/
29-
String APPLICATION_ATOM_XML = "application/atom+xml";
39+
public static String APPLICATION_ATOM_XML = "application/atom+xml";
3040
/**
3141
* Field APPLICATION_FORM_URLENCODED. (value is "application/x-www-form-urlencoded")
3242
*/
33-
String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
43+
public static String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
3444
/**
3545
* Field APPLICATION_JSON. (value is "application/json")
3646
*/
37-
String APPLICATION_JSON = "application/json";
47+
public static String APPLICATION_JSON = "application/json";
3848
/**
3949
* Field APPLICATION_MS_WORD. (value is "application/msword")
4050
*/
41-
String APPLICATION_MS_WORD = "application/msword";
51+
public static String APPLICATION_MS_WORD = "application/msword";
4252

4353
/**
4454
* Field APPLICATION_MS_WORD_DOCX. (value is
4555
* "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
4656
*/
47-
String APPLICATION_MS_WORD_DOCX =
57+
public static String APPLICATION_MS_WORD_DOCX =
4858
"application/vnd.openxmlformats-officedocument.wordprocessingml.document";
4959

5060
/**
5161
* Field APPLICATION_OCTET_STREAM. (value is "application/octet-stream")
5262
*/
53-
String APPLICATION_OCTET_STREAM = "application/octet-stream";
63+
public static String APPLICATION_OCTET_STREAM = "application/octet-stream";
5464
/**
5565
* Field APPLICATION_PDF. (value is "application/pdf")
5666
*/
57-
String APPLICATION_PDF = "application/pdf";
67+
public static String APPLICATION_PDF = "application/pdf";
5868
/**
5969
* Field APPLICATION_SVG_XML. (value is "application/svg+xml")
6070
*/
61-
String APPLICATION_SVG_XML = "application/svg+xml";
71+
public static String APPLICATION_SVG_XML = "application/svg+xml";
6272
/**
6373
* Field APPLICATION_XHTML_XML. (value is "application/xhtml+xml")
6474
*/
65-
String APPLICATION_XHTML_XML = "application/xhtml+xml";
75+
public static String APPLICATION_XHTML_XML = "application/xhtml+xml";
6676
/**
6777
* Field APPLICATION_ZIP. (value is "application/zip")
6878
*/
69-
String APPLICATION_ZIP = "application/zip";
79+
public static String APPLICATION_ZIP = "application/zip";
7080

7181
/**
7282
* Field APPLICATION_XML. (value is "application/xml")
7383
*/
74-
String APPLICATION_XML = "application/xml";
84+
public static String APPLICATION_XML = "application/xml";
7585
/**
7686
* Field AUDIO_OGG. (value is "audio/ogg; codecs=opus")
7787
*/
78-
String AUDIO_OGG = "audio/ogg; codecs=opus";
88+
public static String AUDIO_OGG = "audio/ogg; codecs=opus";
7989
/**
8090
* Field AUDIO_WAV. (value is "audio/wav")
8191
*/
82-
String AUDIO_WAV = "audio/wav";
92+
public static String AUDIO_WAV = "audio/wav";
8393

8494
/**
8595
* Field AUDIO_FLAC. (value is "audio/flac")
8696
*/
87-
String AUDIO_FLAC = "audio/flac";
97+
public static String AUDIO_FLAC = "audio/flac";
8898

8999
/**
90-
* Field AUDIO_RAW. (value is "audio/l16")
100+
* Field AUDIO_RAW. (value is "audio/l16") <br/>
101+
* When using in {@link SpeechToText} a sample rate must be provided
91102
*/
92-
String AUDIO_RAW = "audio/l16";
103+
public static String AUDIO_RAW = "audio/l16";
104+
105+
/**
106+
* Creates an <code>audio/l16</code> media type that includes sample rate
107+
*
108+
* @param rate The sample rate
109+
* @return <code>audio/l16; rate={rate}</code>
110+
* @see SpeechToText#recognizeUsingWebSocket(InputStream, RecognizeOptions, RecognizeCallback)
111+
*/
112+
public static String createAudioRaw(int rate) {
113+
return AUDIO_RAW + "; rate=" + rate;
114+
};
93115

94116
/**
95117
* Field BINARY_FILE. (value is "application/octet-stream")
96118
*/
97-
MediaType BINARY_FILE = MediaType.parse(APPLICATION_OCTET_STREAM);
119+
public static MediaType BINARY_FILE = MediaType.parse(APPLICATION_OCTET_STREAM);
98120

99121
/**
100122
* Field BINARY_OCTET_STREAM. (value is "binary/octet-stream")
101123
*/
102-
String BINARY_OCTET_STREAM = "binary/octet-stream";
124+
public static String BINARY_OCTET_STREAM = "binary/octet-stream";
125+
103126
/**
104127
* Field JSON. (value is "application/json; charset=utf-8")
105128
*/
106-
MediaType JSON = MediaType.parse(APPLICATION_JSON + "; charset=utf-8");
129+
public static MediaType JSON = MediaType.parse(APPLICATION_JSON + "; charset=utf-8");
107130
/**
108131
* Field MEDIA_TYPE_WILDCARD. (value is "*")
109132
*/
110-
String MEDIA_TYPE_WILDCARD = "*";
133+
public static String MEDIA_TYPE_WILDCARD = "*";
111134
/**
112135
* Field MULTIPART_FORM_DATA. (value is "multipart/form-data")
113136
*/
114-
String MULTIPART_FORM_DATA = "multipart/form-data";
137+
public static String MULTIPART_FORM_DATA = "multipart/form-data";
115138
/**
116139
* Field TEXT_CSV. (value is "text/csv")
117140
*/
118-
String TEXT_CSV = "text/csv";
141+
public static String TEXT_CSV = "text/csv";
119142

120143
/**
121144
* Field TEXT_HTML. (value is "text/html")
122145
*/
123-
String TEXT_HTML = "text/html";
146+
public static String TEXT_HTML = "text/html";
124147

125148
/**
126149
* Field TEXT_PLAIN. (value is "text/plain")
127150
*/
128-
String TEXT_PLAIN = "text/plain";
151+
public static String TEXT_PLAIN = "text/plain";
129152

130153
/**
131154
* Field TEXT. (value is "text/plain; charset=utf-8")
132155
*/
133-
MediaType TEXT = MediaType.parse(TEXT_PLAIN + "; charset=utf-8");
156+
public static MediaType TEXT = MediaType.parse(TEXT_PLAIN + "; charset=utf-8");
134157

135158
/**
136159
* Field TEXT_XML. (value is "text/xml")
137160
*/
138-
String TEXT_XML = "text/xml";
161+
public static String TEXT_XML = "text/xml";
139162

140163
/**
141164
* Field WILDCARD. (value is "*\/*")
142165
*/
143-
String WILDCARD = "*/*";
166+
public static String WILDCARD = "*/*";
144167
}
Collapse file

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

Copy file name to clipboardExpand all lines: src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/RecognizeOptions.java
+24-16Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package com.ibm.watson.developer_cloud.speech_to_text.v1;
1515

1616
import com.google.gson.annotations.SerializedName;
17+
import com.ibm.watson.developer_cloud.http.HttpMediaType;
1718
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechSession;
1819
import com.ibm.watson.developer_cloud.util.Validator;
1920

@@ -42,7 +43,7 @@ public static class Builder {
4243
private Double wordAlternativesThreshold;
4344
private Boolean wordConfidence;
4445

45-
46+
4647
private Builder(RecognizeOptions options) {
4748
this.contentType = options.contentType;
4849
this.continuous = options.continuous;
@@ -71,30 +72,37 @@ public Builder() {}
7172
public RecognizeOptions build() {
7273
return new RecognizeOptions(this);
7374
}
74-
75+
7576
/**
7677
* The format of the audio data specified as one of the following values: <br>
7778
* <ul>
7879
* <li><code>audio/flac</code> for Free Lossless Audio Codec (FLAC)</li>
79-
* <li><code>audio/l16</code> for Linear 16-bit Pulse-Code Modulation (PCM)</li>
80+
* <li><code>audio/l16</code> for Linear 16-bit Pulse-Code Modulation (PCM).</li>
8081
* <li><code>audio/wav</code> for Waveform Audio File Format (WAV)</li>
8182
* <li><code>audio/ogg;codecs=opus</code> for Ogg format files that use the opus codec</li>
8283
* </ul>
8384
* .
8485
*
8586
* @param contentType the content type
8687
* @return the recognize options
88+
* @throws IllegalArgumentException when contentType is null or invalid
89+
* @see Use if audio is PCM
8790
*/
8891
public Builder contentType(String contentType) {
8992
Validator.isTrue(MediaType.parse(contentType) != null,
9093
"contentType is not a valid mime audio format. Valid formats start with 'audio/'");
94+
95+
Validator.isTrue(contentType.contains(HttpMediaType.AUDIO_RAW) && contentType.contains("rate"),
96+
"When using PCM the audio rate should be specified.");
97+
9198
this.contentType = contentType;
9299
return this;
93100
}
94101

102+
95103
/**
96-
* If true, multiple final results that represent multiple consecutive phrases separated by pauses
97-
* are returned. Otherwise, the recognition ends after first "end of speech" is detected.
104+
* If true, multiple final results that represent multiple consecutive phrases separated by
105+
* pauses are returned. Otherwise, the recognition ends after first "end of speech" is detected.
98106
*
99107
* @param continuous the continuous
100108
* @return the recognize options
@@ -128,8 +136,8 @@ public Builder interimResults(Boolean interimResults) {
128136
}
129137

130138
/**
131-
* Specifies an array of keyword strings to be matched in the input audio. By default, the service
132-
* does no keyword spotting.
139+
* Specifies an array of keyword strings to be matched in the input audio. By default, the
140+
* service does no keyword spotting.
133141
*
134142
*
135143
* @param keywords the keywords
@@ -143,11 +151,11 @@ public Builder keywords(String[] keywords) {
143151

144152

145153
/**
146-
* Specifies a minimum level of confidence that the service must have to report a matching keyword
147-
* in the input audio. Specify a probability value between 0 and 1 inclusive. A match must have at
148-
* least the specified confidence to be returned. Omit the parameter or specify a value of null
149-
* (the default) to spot no keywords. If you specify a valid threshold, you must also specify at
150-
* least one keyword.
154+
* Specifies a minimum level of confidence that the service must have to report a matching
155+
* keyword in the input audio. Specify a probability value between 0 and 1 inclusive. A match
156+
* must have at least the specified confidence to be returned. Omit the parameter or specify a
157+
* value of null (the default) to spot no keywords. If you specify a valid threshold, you must
158+
* also specify at least one keyword.
151159
*
152160
*
153161
* @param keywordsThreshold the keywords threshold
@@ -214,10 +222,10 @@ public Builder timestamps(Boolean timestamps) {
214222
}
215223

216224
/**
217-
* Specifies a minimum level of confidence that the service must have to report a hypothesis for a
218-
* word from the input audio. Specify a probability value between 0 and 1 inclusive. A hypothesis
219-
* must have at least the specified confidence to be returned as a word alternative. Omit the
220-
* parameter or specify a value of null (the default) to return no word alternatives.
225+
* Specifies a minimum level of confidence that the service must have to report a hypothesis for
226+
* a word from the input audio. Specify a probability value between 0 and 1 inclusive. A
227+
* hypothesis must have at least the specified confidence to be returned as a word alternative.
228+
* Omit the parameter or specify a value of null (the default) to return no word alternatives.
221229
*
222230
*
223231
*
Collapse file

‎src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextTest.java‎

Copy file name to clipboardExpand all lines: src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextTest.java
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ public void testDeleteSessionWithNull() {
106106
service.deleteSession(null).execute();
107107
}
108108

109+
110+
/**
111+
* Test PCM without rate
112+
*/
113+
@Test(expected = IllegalArgumentException.class)
114+
public void testPcmWithoutRate() {
115+
new RecognizeOptions.Builder().contentType(HttpMediaType.AUDIO_RAW).build();
116+
}
117+
118+
/**
119+
* Test PCM with rate
120+
*/
121+
@Test
122+
public void testPcmWithRate() {
123+
new RecognizeOptions.Builder().contentType(HttpMediaType.AUDIO_RAW + "; rate=44000").build();
124+
}
125+
109126
/**
110127
* Test get model.
111128
*/

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.