Skip to content

Commit 310bdd0

Browse files
committed
refactor(speech-to-text): remove compatibility layer for speech to text
BREAKING CHANGE: Deprecated methods in Speech to Text are no longer available. Changed parameter names are no longer interally corrected. To migrate your code, use the methods and parameters currently available with the service as documented here: https://www.ibm.com/watson/developercloud/speech-to-text/api/v1/node.html?node
1 parent 6994d3c commit 310bdd0

3 files changed

Lines changed: 86 additions & 403 deletions

File tree

speech-to-text/v1.ts

Lines changed: 5 additions & 284 deletions
Original file line numberDiff line numberDiff line change
@@ -92,129 +92,6 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
9292
super(options);
9393
}
9494

95-
96-
97-
getModels(params, callback) {
98-
console.warn("WARNING: getModels() was renamed to listModels(). Support for getModels() will be removed in the next major release");
99-
return super.listModels(params, callback);
100-
}
101-
102-
getCustomization(params, callback) {
103-
console.warn("WARNING: getCustomization() was renamed to getLanguageModel(). Support for getCustomization() will be removed in the next major release");
104-
return super.getLanguageModel(params, callback);
105-
}
106-
107-
getRecognitionJob(params, callback) {
108-
console.warn("WARNING: getRecognitionJob() was renamed to checkJob(). Support for getRecognitionJob() will be removed in the next major release");
109-
return super.checkJob(params, callback);
110-
}
111-
112-
createCustomization(params, callback) {
113-
console.warn("WARNING: createCustomization() was renamed to createLanguageModel(). Support for createCustomization() will be removed in the next major release");
114-
if (params && !params.content_type) {
115-
params.content_type = 'application/json';
116-
}
117-
return super.createLanguageModel(params, callback);
118-
}
119-
120-
getRecognitionJobs(params, callback) {
121-
console.warn("WARNING: getRecognitionJobs() was renamed to checkJobs(). Support for getRecognitionJobs() will be removed in the next major release");
122-
return super.checkJobs(params, callback);
123-
}
124-
125-
deleteRecognitionJob(params, callback) {
126-
console.warn("WARNING: deleteRecognitionJob() was renamed to deleteJob(). Support for deleteRecognitionJob() will be removed in the next major release");
127-
return super.deleteJob(params, callback);
128-
}
129-
130-
getCustomizations(params, callback) {
131-
console.warn("WARNING: getCustomizations() was renamed to listLanguageModels(). Support for getCustomizations() will be removed in the next major release");
132-
return super.listLanguageModels(params, callback);
133-
}
134-
135-
createRecognitionJob(params, callback) {
136-
console.warn("WARNING: createRecognitionJob() was renamed to createJob(). Support for createRecognitionJob() will be removed in the next major release");
137-
if (params && Array.isArray(params.events)) {
138-
params.events = params.events.join(',');
139-
}
140-
return super.createJob(params, callback);
141-
}
142-
143-
addCorpus(params, callback) {
144-
if (params && params.name) {
145-
params.corpus_name = params.name;
146-
}
147-
if (params && params.corpus) {
148-
params.corpus_file = params.corpus;
149-
}
150-
return super.addCorpus(params, callback);
151-
}
152-
153-
getCorpus(params, callback) {
154-
if (params && params.name) {
155-
params.corpus_name = params.name;
156-
}
157-
return super.getCorpus(params, callback);
158-
}
159-
160-
deleteCorpus(params, callback) {
161-
if (params && params.name) {
162-
params.corpus_name = params.name;
163-
}
164-
return super.deleteCorpus(params, callback);
165-
}
166-
167-
getCorpora(params, callback) {
168-
console.warn("WARNING: getCorpora() was renamed to listCorpora(). Support for getCorpora() will be removed in the next major release");
169-
return super.listCorpora(params, callback);
170-
}
171-
172-
addWords(params, callback) {
173-
if (params && !params.content_type) {
174-
params.content_type = 'application/json';
175-
}
176-
return super.addWords(params, callback);
177-
}
178-
179-
addWord(params, callback) {
180-
if (params && params.word) {
181-
params.word_name = params.word;
182-
}
183-
if (params && !params.content_type) {
184-
params.content_type = 'application/json';
185-
}
186-
return super.addWord(params, callback);
187-
}
188-
189-
getWords(params, callback) {
190-
console.warn("WARNING: getWords() was renamed to listWords(). Support for getWords() will be removed in the next major release");
191-
return super.listWords(params, callback);
192-
}
193-
194-
getWord(params, callback) {
195-
if (params && params.word) {
196-
params.word_name = params.word;
197-
}
198-
return super.getWord(params, callback);
199-
}
200-
201-
deleteWord(params, callback) {
202-
if (params && params.word) {
203-
params.word_name = params.word;
204-
}
205-
return super.deleteWord(params, callback);
206-
}
207-
208-
trainCustomization(params, callback) {
209-
console.warn("WARNING: trainCustomization() was renamed to trainLanguageModel(). Support for trainCustomization() will be removed in the next major release");
210-
return super.trainLanguageModel(params, callback);
211-
}
212-
213-
resetCustomization(params, callback) {
214-
console.warn("WARNING: resetCustomization() was renamed to resetLanguageModel(). Support for resetCustomization() will be removed in the next major release");
215-
return super.resetLanguageModel(params, callback);
216-
}
217-
21895
/**
21996
* Waits while corpora analysis status is 'being_processes', fires callback once the status is 'analyzed'
22097
*
@@ -234,7 +111,7 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
234111
[
235112
// validate that it has at least one corpus
236113
(next) => {
237-
self.getCorpora(params, (err, res) => {
114+
self.listCorpora(params, (err, res) => {
238115
if (err) {
239116
return next(err);
240117
}
@@ -258,15 +135,15 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
258135
params
259136
);
260137
options.errorFilter = (err) => {
261-
// if it's a timeout error, then getCorpora is called again after params.interval
138+
// if it's a timeout error, then listCorpora is called again after params.interval
262139
// otherwise the error is passed back to the user
263140
// if the params.times limit is reached, the error will be passed to the user regardless
264141
return err.code === SpeechToTextV1.ERR_TIMEOUT;
265142
};
266143
async.retry(
267144
options,
268145
(done) => {
269-
self.getCorpora(params, (err, corpora) => {
146+
self.listCorpora(params, (err, corpora) => {
270147
if (err) {
271148
done(err);
272149
} else if (isProcessing(corpora)) {
@@ -296,157 +173,6 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
296173
);
297174
}
298175

299-
/**
300-
* Creates a HTTP/HTTPS request to /recognize and keep the connection open.
301-
* Sets 'Transfer-Encoding': 'chunked' and prepare the connection to send
302-
* chunk data.
303-
*
304-
* @deprecated use recognizeUsingWebSocket instead
305-
*
306-
* @param {Object} params The parameters
307-
* @param {String} [params.content_type] - The Content-type e.g. audio/l16; rate=48000
308-
* @param {String} [params.session_id] - The session id
309-
* @param {function} callback
310-
*/
311-
recognizeLive(params, callback) {
312-
const missingParams = getMissingParams(params, [
313-
'session_id',
314-
'content_type',
315-
'cookie_session'
316-
]);
317-
318-
if (missingParams) {
319-
callback(missingParams);
320-
return;
321-
}
322-
323-
const serviceUrl = [
324-
this._options.url,
325-
'/v1/sessions/',
326-
params.session_id,
327-
'/recognize'
328-
].join('');
329-
const parts = parse(serviceUrl);
330-
const options = {
331-
agent: false,
332-
host: parts.hostname,
333-
port: parts.port,
334-
path: parts.pathname + (params.continuous ? '?continuous=true' : ''),
335-
method: 'POST',
336-
headers: extend(
337-
{
338-
'Transfer-Encoding': 'chunked',
339-
cookie: 'SESSIONID=' + params.cookie_session,
340-
'Content-type': params.content_type
341-
},
342-
this._options.headers
343-
)
344-
};
345-
const protocol = protocols[parts.protocol.match(/https?/)[0]];
346-
const recognizeReq = protocol.request(options, (result) => {
347-
result.setEncoding('utf-8');
348-
let transcript = '';
349-
350-
result.on('data', (chunk) => {
351-
transcript += chunk;
352-
});
353-
354-
result.on('end', () => {
355-
try {
356-
transcript = formatChunk(transcript);
357-
} catch (e) {
358-
callback(transcript);
359-
return;
360-
}
361-
callback(null, transcript);
362-
});
363-
});
364-
365-
recognizeReq.on('error', (error) => {
366-
callback(error);
367-
});
368-
return recognizeReq;
369-
}
370-
371-
/**
372-
* Result observer for upcoming or ongoing recognition task in the session.
373-
* This request has to be started before POST on recognize finishes,
374-
* otherwise it waits for the next recognition.
375-
*
376-
* @deprecated use recognizeUsingWebSocket instead
377-
*
378-
* @param {Object} params The parameters
379-
* @param {String} [params.session_id] - Session used in the recognition
380-
* @param {boolean} [params.interim_results] - If true, interim results will be returned. Default: false
381-
* @param {Function} callback
382-
*/
383-
observeResult(params, callback) {
384-
const missingParams = getMissingParams(params, [
385-
'session_id',
386-
'cookie_session'
387-
]);
388-
if (missingParams) {
389-
callback(missingParams);
390-
return;
391-
}
392-
const serviceUrl = [
393-
this._options.url,
394-
'/v1/sessions/',
395-
params.session_id,
396-
'/observe_result'
397-
].join('');
398-
const parts = parse(serviceUrl);
399-
const options = {
400-
agent: false,
401-
host: parts.hostname,
402-
port: parts.port,
403-
path:
404-
parts.pathname +
405-
(params.interim_results ? '?interim_results=true' : ''),
406-
method: 'GET',
407-
headers: extend(
408-
{
409-
cookie: 'SESSIONID=' + params.cookie_session,
410-
Accept: 'application/json'
411-
},
412-
this._options.headers
413-
)
414-
};
415-
const protocol = protocols[parts.protocol.match(/https?/)[0]];
416-
const req = protocol.request(options, (result) => {
417-
result.setEncoding('utf-8');
418-
result.on('data', (chunk) => {
419-
try {
420-
chunk = formatChunk(chunk);
421-
} catch (e) {
422-
callback(chunk);
423-
return;
424-
}
425-
callback(null, chunk);
426-
});
427-
});
428-
429-
req.on('error', (error) => {
430-
callback(error);
431-
});
432-
433-
req.end();
434-
435-
return req;
436-
}
437-
438-
/**
439-
* Replaces recognizeLive & friends with a single 2-way stream over websockets
440-
*
441-
* @param {Object} params The parameters
442-
* @return {RecognizeStream}
443-
* @deprecated
444-
*/
445-
createRecognizeStream(params) {
446-
console.warn("WARNING: createRecognizeStream() was renamed to recognizeUsingWebSocket(). Support for createRecognizeStream() will be removed in the next major release");
447-
return this.recognizeUsingWebSocket(params);
448-
}
449-
450176
/**
451177
* Use the recognize function with a single 2-way stream over websockets
452178
*
@@ -554,11 +280,6 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
554280
});
555281
}
556282

557-
deleteCustomization(params, callback) {
558-
console.warn("WARNING: deleteCustomization() was renamed to deleteLanguageModel(). Support for deleteCustomization() will be removed in the next major release");
559-
return super.deleteLanguageModel(params, callback);
560-
}
561-
562283
/**
563284
* Waits while a customization status is 'pending' or 'training', fires callback once the status is 'ready' or 'available'.
564285
*
@@ -585,15 +306,15 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
585306
params
586307
);
587308
options.errorFilter = (err) => {
588-
// if it's a timeout error, then getCustomization is called again after params.interval
309+
// if it's a timeout error, then getLanguageModel is called again after params.interval
589310
// otherwise the error is passed back to the user
590311
// if the params.times limit is reached, the error will be passed to the user regardless
591312
return err.code === SpeechToTextV1.ERR_TIMEOUT;
592313
};
593314
async.retry(
594315
options,
595316
(next) => {
596-
self.getCustomization(params, (err, customization) => {
317+
self.getLanguageModel(params, (err, customization) => {
597318
if (err) {
598319
next(err);
599320
} else if (

0 commit comments

Comments
 (0)