public class SpeechToText extends WatsonService
defaultHeaders, MESSAGE_CODE, MESSAGE_ERROR, skipAuthentication, VERSION
Constructor and Description |
---|
SpeechToText()
Instantiates a new Speech to Text service.
|
SpeechToText(java.lang.String username,
java.lang.String password)
Instantiates a new Speech to Text service by username and password.
|
Modifier and Type | Method and Description |
---|---|
ServiceCall<java.lang.Void> |
addCorpus(java.lang.String customizationId,
java.lang.String corpusName,
java.io.File corpusFile,
java.lang.Boolean allowOverwrite)
Adds a single corpus text file of new training data to the custom language model.
|
ServiceCall<java.lang.Void> |
addWord(java.lang.String customizationId,
Word word)
Add/Updates a custom word to a custom language model.
|
ServiceCall<java.lang.Void> |
addWords(java.lang.String customizationId,
Word... words)
Adds one or more custom words to a custom language model.
|
ServiceCall<Customization> |
createCustomization(java.lang.String name,
SpeechModel baseModel,
java.lang.String description)
Creates the customization.
|
ServiceCall<Customization> |
createCustomization(java.lang.String name,
SpeechModel baseModel,
java.lang.String description,
java.lang.String dialect)
Creates the customization.
|
ServiceCall<RecognitionJob> |
createRecognitionJob(java.io.File audio,
RecognizeOptions recognizeOptions,
RecognitionJobOptions recognitionJobOptions)
Creates an asynchronous recognition request.
|
ServiceCall<SpeechSession> |
createSession()
Creates a session to lock an engine to the session.
|
ServiceCall<SpeechSession> |
createSession(SpeechModel model)
Creates a session to lock an engine to the session.
|
ServiceCall<SpeechSession> |
createSession(java.lang.String model)
Creates a session to lock an engine to the session.
|
ServiceCall<java.lang.Void> |
deleteCorpus(java.lang.String customizationId,
java.lang.String corpusName)
Delete customization corpus.
|
ServiceCall<java.lang.Void> |
deleteCustomization(java.lang.String customizationId)
Delete customization.
|
ServiceCall<java.lang.Void> |
deleteRecognitionJob(java.lang.String id)
Delete recognition.
|
ServiceCall<java.lang.Void> |
deleteSession(SpeechSession session)
Deletes a
SpeechSession . |
ServiceCall<java.lang.Void> |
deleteWord(java.lang.String customizationId,
java.lang.String wordName)
Deletes a custom word from a custom language model.
|
ServiceCall<java.util.List<Corpus>> |
getCorpora(java.lang.String customizationId)
Gets the customization corpus list.
|
ServiceCall<Corpus> |
getCorpus(java.lang.String customizationId,
java.lang.String corpusName)
Gets the specified corpus for the customization.
|
ServiceCall<Customization> |
getCustomization(java.lang.String customizationId)
Gets the customization information.
|
ServiceCall<java.util.List<Customization>> |
getCustomizations(java.lang.String language)
Gets all the customizations belonging to the user.
|
ServiceCall<SpeechModel> |
getModel(java.lang.String modelName)
Gets the speech model based on a given name.
|
ServiceCall<java.util.List<SpeechModel>> |
getModels()
Gets the models.
|
ServiceCall<RecognitionJob> |
getRecognitionJob(java.lang.String id)
Gets the recognition.
|
ServiceCall<java.util.List<RecognitionJob>> |
getRecognitionJobs()
Returns the status and id of all outstanding jobs.
|
ServiceCall<SpeechSessionStatus> |
getRecognizeStatus(SpeechSession session)
Gets the session status.
|
ServiceCall<WordData> |
getWord(java.lang.String customizationId,
java.lang.String wordName)
Gets information about a word from a custom language model.
|
ServiceCall<java.util.List<WordData>> |
getWords(java.lang.String customizationId,
Word.Type type)
Gets information about all the words from a custom language model.
|
ServiceCall<java.util.List<WordData>> |
getWords(java.lang.String customizationId,
Word.Type type,
Word.Sort sort)
Gets information about all the words from a custom language model.
|
ServiceCall<SpeechResults> |
recognize(java.io.File audio)
Recognizes an audio file and returns
SpeechResults . |
ServiceCall<SpeechResults> |
recognize(java.io.File audio,
RecognizeOptions options)
Recognizes an audio file and returns
SpeechResults .Here is an example of how to recognize an audio file: |
okhttp3.WebSocket |
recognizeUsingWebSocket(java.io.InputStream audio,
RecognizeOptions options,
RecognizeCallback callback)
Recognizes an audio
InputStream using a WebSocket .The RecognizeCallback instance will be called every time the service sends SpeechResults .Here is an example of how to recognize an audio file using WebSockets and get interim results: |
ServiceCall<RecognitionCallback> |
registerCallback(java.lang.String callbackUrl,
java.lang.String secret)
Registers a callback URL with the service for use with subsequent asynchronous recognition requests.
|
ServiceCall<java.lang.Void> |
resetCustomization(java.lang.String customizationId)
Resets a custom language model by removing all corpora and words from the model.
|
ServiceCall<java.lang.Void> |
trainCustomization(java.lang.String customizationId,
Customization.WordTypeToAdd wordTypeToAdd)
Initiates the training of a custom language model with new corpora, words, or both.
|
configureHttpClient, createServiceCall, getApiKey, getEndPoint, getName, getToken, processServiceCall, setApiKey, setAuthentication, setDefaultHeaders, setDefaultHeaders, setEndPoint, setSkipAuthentication, setUsernameAndPassword, toString
public SpeechToText()
public SpeechToText(java.lang.String username, java.lang.String password)
username
- the usernamepassword
- the passwordpublic ServiceCall<java.lang.Void> addCorpus(java.lang.String customizationId, java.lang.String corpusName, java.io.File corpusFile, java.lang.Boolean allowOverwrite)
customizationId
- The GUID of the custom language model to which a corpus is to be added. You must make the
request with the service credentials of the model's owner.corpusName
- The name of the corpus that is to be added. The name cannot contain spaces and cannot be the
string user, which is reserved by the service to denote custom words added or modified by the user.corpusFile
- A plain text file that contains the training data for the corpus. Encode the file in UTF-8 if it
contains non-ASCII characters; the service assumes UTF-8 encoding if it encounters non-ASCII characters.allowOverwrite
- Indicates whether the specified corpus is to overwrite an existing corpus with the same name.
If a corpus with the same name already exists, the request fails unless allow_overwrite is set to true; by
default, the parameter is false. The parameter has no effect if a corpus with the same name does not already
exist.public ServiceCall<java.lang.Void> addWord(java.lang.String customizationId, Word word)
customizationId
- The GUID of the custom language model to which a word is to be added. You must make the
request with the service credentials of the model's owner.word
- the word to add/updatepublic ServiceCall<java.lang.Void> addWords(java.lang.String customizationId, Word... words)
customizationId
- The GUID of the custom language model to which words are to be added. You must make the
request with the service credentials of the model's owner.words
- the list of words to be added.public ServiceCall<Customization> createCustomization(java.lang.String name, SpeechModel baseModel, java.lang.String description, java.lang.String dialect)
name
- The customization namebaseModel
- The name of the language model that is to be customized by the new model. e.g:
'en-US_BroadbandModel'.description
- the customization descriptiondialect
- the language dialectpublic ServiceCall<Customization> createCustomization(java.lang.String name, SpeechModel baseModel, java.lang.String description)
name
- The customization namebaseModel
- The name of the language model that is to be customized by the new model. e.g:
'en-US_BroadbandModel'.description
- the customization descriptionpublic ServiceCall<RecognitionJob> createRecognitionJob(java.io.File audio, RecognizeOptions recognizeOptions, RecognitionJobOptions recognitionJobOptions)
audio
- the audiorecognizeOptions
- the recognize optionsrecognitionJobOptions
- the recognition job optionspublic ServiceCall<SpeechSession> createSession()
SpeechSession
public ServiceCall<SpeechSession> createSession(SpeechModel model)
model
- the modelSpeechSession
public ServiceCall<SpeechSession> createSession(java.lang.String model)
model
- the modelSpeechSession
public ServiceCall<java.lang.Void> deleteCorpus(java.lang.String customizationId, java.lang.String corpusName)
customizationId
- The GUID of the custom language model from which the corpus is to be deleted. You must make
the request with the service credentials of the model's owner.corpusName
- the corpus namepublic ServiceCall<java.lang.Void> deleteCustomization(java.lang.String customizationId)
customizationId
- The GUID of the custom language model being deleted. You must make the request with the
service credentials of the model's owner.public ServiceCall<java.lang.Void> deleteRecognitionJob(java.lang.String id)
id
- the idpublic ServiceCall<java.lang.Void> deleteSession(SpeechSession session)
SpeechSession
.session
- the speech session to deletepublic ServiceCall<java.lang.Void> deleteWord(java.lang.String customizationId, java.lang.String wordName)
customizationId
- The GUID of the custom language model from which the word is being deleted. You must make
the request with the service credentials of the model's owner.wordName
- the word namepublic ServiceCall<java.util.List<Corpus>> getCorpora(java.lang.String customizationId)
customizationId
- The GUID of the custom language model whose corpora is being queried. You must make the
request with the service credentials of the model's owner.public ServiceCall<Corpus> getCorpus(java.lang.String customizationId, java.lang.String corpusName)
customizationId
- The GUID of the custom language model whose corpus is to be returned. You must make the
request with the service credentials of the model's owner.corpusName
- The name of the corpus that is to be returned.public ServiceCall<Customization> getCustomization(java.lang.String customizationId)
customizationId
- The GUID of the custom language model being queried. You must make the request with the
service credentials of the model's owner.public ServiceCall<java.util.List<Customization>> getCustomizations(java.lang.String language)
language
- The language for which custom models are to be returned.public ServiceCall<SpeechModel> getModel(java.lang.String modelName)
modelName
- the model nameSpeechModel
public ServiceCall<java.util.List<SpeechModel>> getModels()
SpeechModel
spublic ServiceCall<RecognitionJob> getRecognitionJob(java.lang.String id)
id
- the idpublic ServiceCall<java.util.List<RecognitionJob>> getRecognitionJobs()
public ServiceCall<SpeechSessionStatus> getRecognizeStatus(SpeechSession session)
recognize(File, RecognizeOptions)
.session
- the speech sessionpublic ServiceCall<WordData> getWord(java.lang.String customizationId, java.lang.String wordName)
customizationId
- The GUID of the custom language model containing the word being queried. You must make the
request with the service credentials of the model's owner.wordName
- the word namepublic ServiceCall<java.util.List<WordData>> getWords(java.lang.String customizationId, Word.Type type)
customizationId
- The GUID of the custom language model to which a corpus is to be added. You must make the
request with the service credentials of the model's owner.type
- the word type. Possible values are: ALL, USER or CORPORA.public ServiceCall<java.util.List<WordData>> getWords(java.lang.String customizationId, Word.Type type, Word.Sort sort)
customizationId
- The GUID of the custom language model to which a corpus is to be added. You must make the
request with the service credentials of the model's owner.type
- the word type. Possible values are: ALL, USER or CORPORA. The default is ALL.sort
- the sort order of the results. Possible values are: ALPHA, PLUS_ALPHA, MINUS_ALPHA, COUNT, PLUS_COUNT,
and MINUS_COUNT. The default is ALPHA/PLUS_ALPHA.public ServiceCall<SpeechResults> recognize(java.io.File audio)
SpeechResults
. It will try to recognize the audio format based on the
file extension.SpeechToText service = new SpeechToText(); service.setUsernameAndPassword("USERNAME", "PASSWORD"); service.setEndPoint("SERVICE_URL"); SpeechResults results = service.recognize(new File("sample1.wav")).execute(); System.out.println(results);
audio
- the audio fileSpeechResults
java.lang.IllegalArgumentException
- if the file extension doesn't match a valid audio typepublic ServiceCall<SpeechResults> recognize(java.io.File audio, RecognizeOptions options)
SpeechResults
.SpeechToText service = new SpeechToText(); service.setUsernameAndPassword("USERNAME", "PASSWORD"); service.setEndPoint("SERVICE_URL"); RecognizeOptions options = new RecognizeOptions().maxAlternatives(3).continuous(true); File audio = new File("sample1.wav"); SpeechResults results = service.recognize(audio, options).execute(); System.out.println(results);
audio
- the audio fileoptions
- the recognize optionsSpeechResults
public okhttp3.WebSocket recognizeUsingWebSocket(java.io.InputStream audio, RecognizeOptions options, RecognizeCallback callback)
InputStream
using a WebSocket
.RecognizeCallback
instance will be called every time the service sends SpeechResults
.SpeechToText service = new SpeechToText(); service.setUsernameAndPassword("USERNAME", "PASSWORD"); service.setEndPoint("SERVICE_URL"); RecognizeOptions options = new RecognizeOptions().maxAlternatives(2).continuous(true); FileInputStream audio = new FileInputStream("sample1.wav"); service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() { @Override public void onTranscript(SpeechResults speechResults) { System.out.println(speechResults); } });
audio
- the audio InputStream
options
- the RecognizeOptions
callback
- the RecognizeCallback
instance where results will be sendWebSocket
public ServiceCall<RecognitionCallback> registerCallback(java.lang.String callbackUrl, java.lang.String secret)
GET
request from the service, after which the service responds with response code 201 to the
original registration request. secret
with the request, the service uses it as a key to calculate an
HMAC-SHA1
signature of a random challenge string in its response to the request. The signature
provides authentication and data integrity for HTTP communications.callbackUrl
- the callback urlsecret
- the secretpublic ServiceCall<java.lang.Void> resetCustomization(java.lang.String customizationId)
customizationId
- The GUID of the custom language model being reset. You must make the request with the
service credentials of the model's owner.public ServiceCall<java.lang.Void> trainCustomization(java.lang.String customizationId, Customization.WordTypeToAdd wordTypeToAdd)
getCustomization(String)
method to poll the model's status.customizationId
- The GUID of the custom language model being trained. You must make the request with the
service credentials of the model's owner.wordTypeToAdd
- the word type to add