-1

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;
 }  
Xe Pueblos
  • 21
  • 1
  • 6
  • This Question is drafted very ambiguously. Can you try to [re-write (edit)](https://stackoverflow.com/help/how-to-ask) this question to make it more understandable? also I noticed that you are using `wss://`, so this is a websocket interface situation. Am I right? – RC0993 Jan 30 '19 at 06:53
  • ok so what I am trying to do is to turn the string above from the usual username password and put the api key instead. the instructions that they have over at [link(]https://github.com/watson-developer-cloud/speech-android-sdk) is very outdated and I was wondering if there is anyway wherein these codes can be modified. – Xe Pueblos Jan 31 '19 at 15:36
  • Are you able to authenticate yourself? Are you sure you are suppose to use the `apikey`? how are you passing the `apikey`? [Refer this document](https://console.bluemix.net/docs/services/watson/getting-started-iam.html#iam), probably you are missing something. – RC0993 Feb 01 '19 at 07:18
  • I am unable to authenticate it as for I do not know how. the ones in the link is for a curl and js version – Xe Pueblos Feb 01 '19 at 23:19
  • If you have solved this issue please add valid comments and close this – RC0993 Feb 05 '19 at 04:23
  • it has not been solved. I have yet to get any answers on a sample code on how it is possible to do so. – Xe Pueblos Feb 05 '19 at 04:45
  • Can you Edit the question and upload the screenshot of error? Also do you know how to use Wireshark (if not then google it) and try to find out at which stage your error is generating? For me (in C++) I wasn't able to connect to the Watson webserver with just `apikey`. When I checked the Wireshark entries it was clear that the program was successful till *SSL handshake* and generated error on the *Websocket handshake*. – RC0993 Feb 05 '19 at 05:16

2 Answers2

0

This might help you to authenticate yourself with IBM watson websocket handshake.

To get the authentication-token you need to run the following cURL command. This can be included in your program prior to the connection (websocket handshake).

curl -k -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Accept: application/json" --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" --data-urlencode "apikey={your apikey}" "https://iam.bluemix.net/identity/token"

You will get the token as response.

And use this token for your authentication at handshake.

Below is given how I used it for my Project in C++ using boost library.

ws_.async_handshake_ex(host_, "/speech-to-text/api/v1/recognize",[](request_type& reqHead){reqHead.insert(http::field::authorization,"Bearer {my_token}");},std::bind( &session::on_handshake, shared_from_this(), std::placeholders::_1));

Try this instead of your apikey. Don't forget to add "Bearer"

Follow this link for more details - https://console.bluemix.net/docs/services/watson/getting-started-iam.html

Youu may try doing the same in your language.

RC0993
  • 898
  • 1
  • 13
  • 44
  • can curl be used on android environments? – Xe Pueblos Feb 03 '19 at 05:34
  • Hey, check this out [This link](https://stackoverflow.com/questions/4952169/using-curl-in-android) – RC0993 Feb 03 '19 at 05:43
  • the tutorial [link](http://thesoftwarerogue.blogspot.com/2010/05/porting-of-libcurl-to-android-os-using.html)[link] provided that in order for me to set this up, I would need to have a linux environment. atm I have a windows 10 one. – Xe Pueblos Feb 03 '19 at 06:09
  • @user896273 You are probably having handshake issue, that should not depend on OS. Please google your programing language's preferences to do websocket handshake, and how to put the authentication as request headers. – RC0993 Feb 03 '19 at 06:41
0

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.

Logan Patiño
  • 91
  • 1
  • 10