ibm watson speech to text - android

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.

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.

Related

Microsoft Azure Translator Android API not working

I was trying to make a text translator app using Microsoft-translator-API but I am not able to receive any response from this API, I always get this message:
[microsoft-translator-api] Error retrieving translation: Unable to resolve host "datamarket.accesscontrol.windows.net": No address associated with hostname
even I have given correct client Id and client secret Id.
I tried this link but I don't know where to put the JSON-Simple.jar file. I tried this link too but still with no success. I am pasting my code below:
public String translateText() throws Exception {
Translate.setClientId("whateveritis");
Translate.setClientSecret("whateveritis");
translatedText = Translate.execute(
userText.getText().toString(),
languages[sEnterLan.getSelectedItemPosition()],
languages[sTransLan.getSelectedItemPosition()]);
Language detectedLanguage = Detect.execute(userText.getText()
.toString());
this.detectedLanguage = detectedLanguage.getName(Language.ENGLISH);
return translatedText;
}
By calling above function I can receive the translated text into a string variable but every time I get an exception.
According to your code and reference links, I think you were using the third party Java wrapper boatmeme/microsoft-translator-java-api for MS Azure Translator API. However, it's an old Java wrapper which wrappered the old & unavailable APIs from the old site Azure datamarket. There is a notice at this site, and all origin APIs had been migrated to Azure subscription.
DataMarket and Data Services are being retired and will stop accepting new orders after 12/31/2016. Existing subscriptions will be retired and cancelled starting 3/31/2017. Please reach out to your service provider for options if you want to continue service.
So I suggested that you can try to refer to my answer for the other SO thread Microsoft Translator API Java, How to get client new ID with Azure to create a cognitive service for Translator Text API on Azure portal and use it via the new REST APIs.
Hope it helps.

Stripe.apiKey not resolving in Android

I'm using Stripe as a payment processor in my Android app and trying to charge a card as described by the documentation: https://stripe.com/docs/charges
My issue specifically is that it can not resolve Stripe.apiKey, or can not resolve symbol apiKey
The code that I'm implementing from the documentation:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_********************";//this is where i hit a wall
// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:
String token = request.getParameter("stripeToken");
// Charge the user's card:
Map<String, Object> params = new HashMap<String, Object>();
params.put("amount", 1000);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", token);
Charge charge = Charge.create(params);
I have also imported import com.stripe.android.*; at the top of my file.
In my Gradle file I have imported the Stripe libraries:
compile 'com.stripe:stripe-android:2.0.2'
Why isn't Android able to resolve Stripe.apiKey?
The code you provided is server-side Java code for creating a charge using a token. It is not meant to be used from an Android application.
A payment flow with Stripe is divided in two steps:
client-side, in your frontend code, you collect and tokenize the user's payment information (using Checkout or Stripe.js for a web application, or the iOS / Android SDKs for a native mobile application)
server-side, in your backend code, you use the resulting token in an API request, e.g. to create a charge or a customer object.
The first step is done with your publishable API key (pk_...). The second step is done with your secret API key (sk_...).
You must never share the secret API key with your frontend code, otherwise an attacker could retrieve it and use it to issue API requests on your behalf.
To solve Stripe.apikey cannot resolve, change Stripe.apiKey to
com.stripe.Stripe.apiKey = "Your secret";
Try: Stripe stripe = new Stripe("pk_test_6pRNASCoBOKtIshFeQd4XMUh");
For more info check out: https://stripe.com/docs/mobile/android#credit-card-form

Sending HTTP request from Android app

Currently in cURL I can run a basic request like this:
curl -u username:token https://api.mywebsite.com -H "Accept: application/custom-header"
It authenticates, it picks up the custom header and everything is great.
However, I want to do this from an Android app. I had a look at HttpClient but it was deprecated at API level 22. So now I'm trying to find something else to do the job.
What is the current/best way to do this from an Android app?
Thanks
You can use Volley Library of google for the Network call check this Volley site

How to use Client Key instead of Rest Api Key for Android on Parse.com Rest Api requests

In Parse.com Rest API documentation it says this:
You should not use the REST API Key in client apps (i.e. code you distribute to your customers). If the Parse SDK is available for your client platform, we recommend using our SDK instead of the REST API. If you must call the REST API directly from the client, you should use the corresponding client-side Parse key for that plaform (e.g. Client Key for iOS/Android, or .NET Key for Windows/Xamarin/Unity).
In my retrofit api I have the following code with header:
#Headers({"X-Parse-Application-Id: " + ParseEndPointConfig.PARSE_APPLICATION_ID, "X-Parse-REST-API-Key: " + ParseEndPointConfig.PARSE_CLIENT_KEY})
#POST("classes/Xxx")
Observable<XxxParseObject> createXxx(#Body XxxParseObject circle);
As stated in the docs, using Rest Api Key is not recommended. It is suggested to use Client key for Android. How should the header look like if I used Client key for authentication? Is there any example on using Client key instead of Rest Api key for client side applications?
Short answer: use the header X-Parse-Client-Key in your REST call.
Full explanation: When you look at the Parse REST docs, you frequently see examples like this:
curl -X POST \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/GameScore
Note how the parse headers start with X-Parse-. I previously needed to figure out how to use dotNET key for parse-push-plugin. On a hunch, I searched the dotNET SDK for X-Parse-, and found the header to be X-Parse-Windows-Key.
Doing the same thing with the Java SDK, you would find the following declarations in ParseRESTCommand.java
static final String HEADER_APPLICATION_ID = "X-Parse-Application-Id";
static final String HEADER_CLIENT_KEY = "X-Parse-Client-Key";

how to call RESTful web service from android?

I have written REST web service in netbean IDE using jersey framework and java. For every request user need to provide username and password , I know the authentication is not good.
Using curl command like :
curl -u username:password -X PUT http://localhsot:8080/user
Now I want to call REST web service from android class.What should I write? I am new to android. I have a android class which use DefaultHttpClient and CredentialUsernameAndPassword.
But when i run in eclipse, sometime I get runtime exception or sdk exception.
Do anyone give me sample code and suggestion?
thanks
Do you use basic authentication? if so: use this.
if (username != null && password != null) {
client.getCredentialsProvider().setCredentials(
new AuthScope(null, -1),
new UsernamePasswordCredentials(username, password));
}
or you can add those in a header as setHeader("Authentication", "Basic "+Base64EncodedString(username,pass);
What you are doing is using Proxy authentication. why?
this article may also be helpful somehow:
link
also the -u stands for the ntlm authorization so maybe look into that too. there were some topics where it said it is not supported on android or something but i am sure if you need it you can make a workaround.

Categories

Resources