public class SpeechToText extends WatsonService
defaultHeaders, MESSAGE_CODE, MESSAGE_ERROR, skipAuthentication, VERSION
Constructor and Description |
---|
SpeechToText()
Instantiates a new Speech to Text service.
|
SpeechToText(String username,
String password)
Instantiates a new Speech to Text service by username and password.
|
Modifier and Type | Method and Description |
---|---|
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(String model)
Creates a session to lock an engine to the session.
|
ServiceCall<Void> |
deleteSession(SpeechSession session)
Deletes a
SpeechSession . |
ServiceCall<SpeechModel> |
getModel(String modelName)
Gets the speech model based on a given name.
|
ServiceCall<List<SpeechModel>> |
getModels()
Gets the models.
|
ServiceCall<SpeechSessionStatus> |
getRecognizeStatus(SpeechSession session)
Gets the session status.
|
ServiceCall<SpeechResults> |
recognize(File audio)
Recognizes an audio file and returns
SpeechResults . |
ServiceCall<SpeechResults> |
recognize(File audio,
RecognizeOptions options)
Recognizes an audio file and returns
SpeechResults .Here is an example of how to recognize an audio file: |
void |
recognizeUsingWebSocket(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: |
configureHttpClient, createServiceCall, getApiKey, getEndPoint, getName, getToken, processServiceCall, setApiKey, setAuthentication, setDefaultHeaders, setEndPoint, setSkipAuthentication, setUsernameAndPassword, toString
public ServiceCall<SpeechSession> createSession()
SpeechSession
public ServiceCall<SpeechSession> createSession(SpeechModel model)
model
- the modelSpeechSession
public ServiceCall<SpeechSession> createSession(String model)
model
- the modelSpeechSession
public ServiceCall<Void> deleteSession(SpeechSession session)
SpeechSession
.session
- the speech session to deletepublic ServiceCall<SpeechModel> getModel(String modelName)
modelName
- the model nameSpeechModel
public ServiceCall<List<SpeechModel>> getModels()
SpeechModel
spublic ServiceCall<SpeechSessionStatus> getRecognizeStatus(SpeechSession session)
recognize(File, RecognizeOptions)
.session
- the speech sessionpublic ServiceCall<SpeechResults> recognize(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
IllegalArgumentException
- if the file extension doesn't match a valid audio typepublic ServiceCall<SpeechResults> recognize(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 void recognizeUsingWebSocket(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 input streamoptions
- the recognize optionscallback
- the callbackCopyright © 2015–2016 IBM Watson. All rights reserved.