简体   繁体   中英

ibm watson speech to text

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;
 }  

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM