public class SpeechToText extends WatsonService
VERSION| Constructor and Description |
|---|
SpeechToText()
Instantiates a new speech to text.
|
| Modifier and Type | Method and Description |
|---|---|
SpeechSession |
createSession()
Create a session to lock an engine to the session.
|
SpeechSession |
createSession(SpeechModel model)
Create a session to lock an engine to the session.
|
SpeechSession |
createSession(String model)
Create a session to lock an engine to the session.
|
void |
deleteSession(SpeechSession session)
Delete a session.
|
SpeechModel |
getModel(String name)
Gets the speech model.
|
List<SpeechModel> |
getModels()
Gets the models.
|
SessionStatus |
getRecognizeStatus(SpeechSession session)
Gets the session status.
|
SpeechResults |
recognize(File audio)
Recognizes an audio file and returns
SpeechResults. |
SpeechResults |
recognize(File audio,
RecognizeOptions options)
Recognizes an audio file and returns
SpeechResults.Here is an example of how to recognize an audio file: |
SpeechResults |
recognize(File audio,
String contentType)
Deprecated.
Deprecated in 2.6.0
Use recognize(File, RecognizeOptions) |
SpeechResults |
recognize(File audio,
String contentType,
RecognizeOptions options)
Deprecated.
Deprecated in 2.6.0
Use recognize(File, RecognizeOptions) |
void |
recognizeUsingWebSockets(InputStream audio,
RecognizeOptions options,
RecognizeDelegate delegate)
Recognizes an audio
InputStream using WebSockets. |
configureHttpClient, execute, executeRequest, executeWithoutResponse, getApiKey, getEndPoint, getName, getToken, setApiKey, setAuthentication, setDefaultHeaders, setEndPoint, setUsernameAndPassword, toStringpublic SpeechSession createSession()
SpeechSessionpublic SpeechSession createSession(SpeechModel model)
model - the modelSpeechSessionpublic SpeechSession createSession(String model)
model - the modelSpeechSessionpublic void deleteSession(SpeechSession session)
session - the speech sessionpublic SpeechModel getModel(String name)
name - the namepublic List<SpeechModel> getModels()
public SessionStatus getRecognizeStatus(SpeechSession session)
recognize(File, String, RecognizeOptions)
.session - the speech sessionpublic 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"));
System.out.println(results);
audio - the audio fileSpeechResultsIllegalArgumentException - if the file extension doesn't match a valid audio typepublic 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);
SpeechResults results = service.recognize(new File("sample1.wav"), options);
System.out.println(results);
audio - the audiooptions - the optionspublic SpeechResults recognize(File audio, String contentType)
recognize(File, RecognizeOptions)SpeechResults.audio - the audio filecontentType - the media type of the audio.SpeechResultspublic SpeechResults recognize(File audio, String contentType, RecognizeOptions options)
recognize(File, RecognizeOptions)SpeechResults.audio - the audio filecontentType - the media type of the audio. If you use the audio/l16 MIME type, specify the
rate and channels.options - the RecognizeOptionsSpeechResultspublic void recognizeUsingWebSockets(InputStream audio, RecognizeOptions options, RecognizeDelegate delegate)
InputStream using WebSockets. The RecognizeDelegate
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().continuous(true).interimResults(true);
service.recognizeWS(new FileInputStream("sample1.wav"), options, new BaseRecognizeDelegate() {
@Override
public void onMessage(SpeechResults speechResults) {
System.out.println(speechResults);
}
});
audio - the audio input streamoptions - the recognize optionsdelegate - the delegateCopyright © 2015–2016. All rights reserved.