anyone know how to turn this code into an api key for watson speech to text?
<!-- STT default credentials -->
<string name="STTdefaultUsername">yyyyyyyy</string>
<string name="STTdefaultPassword">xxxxxxxx</string>
<string name="STTdefaultTokenFactory">https://stream.watsonplatform.net/speech-to-text/api</string>
<!-- TTS default credentials -->
<string name="TTSdefaultUsername">yyyyyyyy</string>
<string name="TTSdefaultPassword">xxxxxxx</string>
<string name="TTSdefaultTokenFactory">https://stream.watsonplatform.net/text-to-speech/api</string>
it is then called below
private boolean initSTT() {
// initialize the connection to the Watson STT service
String username = getString(R.string.STTdefaultUsername);
String password = getString(R.string.STTdefaultPassword);
String tokenFactoryURL = getString(R.string.STTdefaultTokenFactory);
String serviceURL = "wss://stream.watsonplatform.net/speech-to-text/api";
SpeechConfiguration sConfig = new SpeechConfiguration(SpeechConfiguration.AUDIO_FORMAT_OGGOPUS);
SpeechToText.sharedInstance().initWithContext(this.getHost(serviceURL), getActivity().getApplicationContext(), sConfig);
// Basic Authentication
SpeechToText.sharedInstance().setCredentials(username, password);
SpeechToText.sharedInstance().setModel(getString(R.string.modelDefault));
SpeechToText.sharedInstance().setDelegate(this);
return true;
}
The Android SDK is built to work with the Java SDK primarily. The Java SDK handles most of the authentication and HTTP logic while the Android SDK just adds things on to get it to work on mobile devices. A deprecated link for it was posted above, so for reference, this is where you can find the Android SDK.
The Java SDK README is where you can find most information about getting started. For this case, you can find help in this section.
To put everything here, if you have your API key in your resources, you can do the following:
SpeechToText service = new SpeechToText();
IamOptions options = new IamOptions.Builder()
.apiKey(R.string.stt_api_key) // this is your API key
.build();
service.setIamCredentials(options);
Again, you'll need to bring in the Java SDK as a dependency for this. The latest version to add to your Gradle config is:
compile 'com.ibm.watson.developer_cloud:java-sdk:6.14.0'
The SDK will handle making the correct API calls in the backend and you should now be able to make authenticated API calls using that service
object.