|
13 | 13 | */ |
14 | 14 | package com.ibm.watson.developer_cloud.http; |
15 | 15 |
|
| 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 | + |
16 | 22 | import okhttp3.MediaType; |
17 | 23 |
|
18 | 24 | /** |
|
21 | 27 | * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7">HTTP/1.1 section |
22 | 28 | * 3.7</a> |
23 | 29 | */ |
24 | | -public interface HttpMediaType { |
| 30 | +public class HttpMediaType { |
| 31 | + |
| 32 | + private HttpMediaType() { |
| 33 | + |
| 34 | + } |
25 | 35 |
|
26 | 36 | /** |
27 | 37 | * Field APPLICATION_ATOM_XML. (value is "application/atom+xml") |
28 | 38 | */ |
29 | | - String APPLICATION_ATOM_XML = "application/atom+xml"; |
| 39 | + public static String APPLICATION_ATOM_XML = "application/atom+xml"; |
30 | 40 | /** |
31 | 41 | * Field APPLICATION_FORM_URLENCODED. (value is "application/x-www-form-urlencoded") |
32 | 42 | */ |
33 | | - String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded"; |
| 43 | + public static String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded"; |
34 | 44 | /** |
35 | 45 | * Field APPLICATION_JSON. (value is "application/json") |
36 | 46 | */ |
37 | | - String APPLICATION_JSON = "application/json"; |
| 47 | + public static String APPLICATION_JSON = "application/json"; |
38 | 48 | /** |
39 | 49 | * Field APPLICATION_MS_WORD. (value is "application/msword") |
40 | 50 | */ |
41 | | - String APPLICATION_MS_WORD = "application/msword"; |
| 51 | + public static String APPLICATION_MS_WORD = "application/msword"; |
42 | 52 |
|
43 | 53 | /** |
44 | 54 | * Field APPLICATION_MS_WORD_DOCX. (value is |
45 | 55 | * "application/vnd.openxmlformats-officedocument.wordprocessingml.document") |
46 | 56 | */ |
47 | | - String APPLICATION_MS_WORD_DOCX = |
| 57 | + public static String APPLICATION_MS_WORD_DOCX = |
48 | 58 | "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; |
49 | 59 |
|
50 | 60 | /** |
51 | 61 | * Field APPLICATION_OCTET_STREAM. (value is "application/octet-stream") |
52 | 62 | */ |
53 | | - String APPLICATION_OCTET_STREAM = "application/octet-stream"; |
| 63 | + public static String APPLICATION_OCTET_STREAM = "application/octet-stream"; |
54 | 64 | /** |
55 | 65 | * Field APPLICATION_PDF. (value is "application/pdf") |
56 | 66 | */ |
57 | | - String APPLICATION_PDF = "application/pdf"; |
| 67 | + public static String APPLICATION_PDF = "application/pdf"; |
58 | 68 | /** |
59 | 69 | * Field APPLICATION_SVG_XML. (value is "application/svg+xml") |
60 | 70 | */ |
61 | | - String APPLICATION_SVG_XML = "application/svg+xml"; |
| 71 | + public static String APPLICATION_SVG_XML = "application/svg+xml"; |
62 | 72 | /** |
63 | 73 | * Field APPLICATION_XHTML_XML. (value is "application/xhtml+xml") |
64 | 74 | */ |
65 | | - String APPLICATION_XHTML_XML = "application/xhtml+xml"; |
| 75 | + public static String APPLICATION_XHTML_XML = "application/xhtml+xml"; |
66 | 76 | /** |
67 | 77 | * Field APPLICATION_ZIP. (value is "application/zip") |
68 | 78 | */ |
69 | | - String APPLICATION_ZIP = "application/zip"; |
| 79 | + public static String APPLICATION_ZIP = "application/zip"; |
70 | 80 |
|
71 | 81 | /** |
72 | 82 | * Field APPLICATION_XML. (value is "application/xml") |
73 | 83 | */ |
74 | | - String APPLICATION_XML = "application/xml"; |
| 84 | + public static String APPLICATION_XML = "application/xml"; |
75 | 85 | /** |
76 | 86 | * Field AUDIO_OGG. (value is "audio/ogg; codecs=opus") |
77 | 87 | */ |
78 | | - String AUDIO_OGG = "audio/ogg; codecs=opus"; |
| 88 | + public static String AUDIO_OGG = "audio/ogg; codecs=opus"; |
79 | 89 | /** |
80 | 90 | * Field AUDIO_WAV. (value is "audio/wav") |
81 | 91 | */ |
82 | | - String AUDIO_WAV = "audio/wav"; |
| 92 | + public static String AUDIO_WAV = "audio/wav"; |
83 | 93 |
|
84 | 94 | /** |
85 | 95 | * Field AUDIO_FLAC. (value is "audio/flac") |
86 | 96 | */ |
87 | | - String AUDIO_FLAC = "audio/flac"; |
| 97 | + public static String AUDIO_FLAC = "audio/flac"; |
88 | 98 |
|
89 | 99 | /** |
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 |
91 | 102 | */ |
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 | + }; |
93 | 115 |
|
94 | 116 | /** |
95 | 117 | * Field BINARY_FILE. (value is "application/octet-stream") |
96 | 118 | */ |
97 | | - MediaType BINARY_FILE = MediaType.parse(APPLICATION_OCTET_STREAM); |
| 119 | + public static MediaType BINARY_FILE = MediaType.parse(APPLICATION_OCTET_STREAM); |
98 | 120 |
|
99 | 121 | /** |
100 | 122 | * Field BINARY_OCTET_STREAM. (value is "binary/octet-stream") |
101 | 123 | */ |
102 | | - String BINARY_OCTET_STREAM = "binary/octet-stream"; |
| 124 | + public static String BINARY_OCTET_STREAM = "binary/octet-stream"; |
| 125 | + |
103 | 126 | /** |
104 | 127 | * Field JSON. (value is "application/json; charset=utf-8") |
105 | 128 | */ |
106 | | - MediaType JSON = MediaType.parse(APPLICATION_JSON + "; charset=utf-8"); |
| 129 | + public static MediaType JSON = MediaType.parse(APPLICATION_JSON + "; charset=utf-8"); |
107 | 130 | /** |
108 | 131 | * Field MEDIA_TYPE_WILDCARD. (value is "*") |
109 | 132 | */ |
110 | | - String MEDIA_TYPE_WILDCARD = "*"; |
| 133 | + public static String MEDIA_TYPE_WILDCARD = "*"; |
111 | 134 | /** |
112 | 135 | * Field MULTIPART_FORM_DATA. (value is "multipart/form-data") |
113 | 136 | */ |
114 | | - String MULTIPART_FORM_DATA = "multipart/form-data"; |
| 137 | + public static String MULTIPART_FORM_DATA = "multipart/form-data"; |
115 | 138 | /** |
116 | 139 | * Field TEXT_CSV. (value is "text/csv") |
117 | 140 | */ |
118 | | - String TEXT_CSV = "text/csv"; |
| 141 | + public static String TEXT_CSV = "text/csv"; |
119 | 142 |
|
120 | 143 | /** |
121 | 144 | * Field TEXT_HTML. (value is "text/html") |
122 | 145 | */ |
123 | | - String TEXT_HTML = "text/html"; |
| 146 | + public static String TEXT_HTML = "text/html"; |
124 | 147 |
|
125 | 148 | /** |
126 | 149 | * Field TEXT_PLAIN. (value is "text/plain") |
127 | 150 | */ |
128 | | - String TEXT_PLAIN = "text/plain"; |
| 151 | + public static String TEXT_PLAIN = "text/plain"; |
129 | 152 |
|
130 | 153 | /** |
131 | 154 | * Field TEXT. (value is "text/plain; charset=utf-8") |
132 | 155 | */ |
133 | | - MediaType TEXT = MediaType.parse(TEXT_PLAIN + "; charset=utf-8"); |
| 156 | + public static MediaType TEXT = MediaType.parse(TEXT_PLAIN + "; charset=utf-8"); |
134 | 157 |
|
135 | 158 | /** |
136 | 159 | * Field TEXT_XML. (value is "text/xml") |
137 | 160 | */ |
138 | | - String TEXT_XML = "text/xml"; |
| 161 | + public static String TEXT_XML = "text/xml"; |
139 | 162 |
|
140 | 163 | /** |
141 | 164 | * Field WILDCARD. (value is "*\/*") |
142 | 165 | */ |
143 | | - String WILDCARD = "*/*"; |
| 166 | + public static String WILDCARD = "*/*"; |
144 | 167 | } |