Skip to content
This repository has been archived by the owner on Jul 20, 2019. It is now read-only.

Quick Start Guide #7

Closed
KeyOnTech opened this issue Feb 3, 2016 · 4 comments
Closed

Quick Start Guide #7

KeyOnTech opened this issue Feb 3, 2016 · 4 comments
Assignees

Comments

@KeyOnTech
Copy link

Quick Guide to getting started with IBM Bluemix Watson Android SDK

I am writing this to help anyone who is going through or went through what I did to get the example up and running.

To get the Android SPEECH TO TEXT and TEXT TO SPEECH working following these instructions, I am writing them as I am doing them as of 2-1-2016.

First create an IBM BlueMix account
https://console.ng.bluemix.net

Once created make the page full screen…

Go to the dashboard
https://console.ng.bluemix.net/
and click dashboard on the top right
Click Create a Space on top left
name it serviceTEST ( whatever you want… )
Once completed click Create App
Web App
SDK Node Js App
click Continue
name it serviceTESTApp1 ( whatever you want… ) If you get a weird error message that probably means someone is using that name just a number or 2 to the end… serviceTESTApp12345 etc…
click Finish

Hit the back or left arrow on the top left of the page
You will see 1 CF App
Now we need to make our services, you CANNOT AS OF THIS WRITING make a service without an app…

Click on Services
click Use Services APIs
click on Speech to Text
on top right click on the App drop down and you will see your new app serviceTESTApp1
Select it and click Create

It will ask to ReStage, say YES

hit the back arrow on the top left
You will now see Services has 1

Click Services and click Speech to Text
click Service Credentials on the left
click add Credentials on the right
name it serviceTESTApp1-STT (whatever you want or just leave the default…)

Now you will see your credentials, you need these for the app

Open a notepad session on Windows or Notes session on Mac and copy all of this block of text you will need this for the android app

{
"credentials": {
"url": "https://stream.watsonplatform.net/speech-to-text/api",
"username": “yyyyyyyyyyyy”,
"password": “XXXXXXX”
}
}

Now lets make the Text to Speech Service same steps…

Hit the back or left arrow on the top left of the page

Click on Services
click Use Services APIs
click on Text to Speech
on top right click on the App drop down and you will see your new app serviceTESTApp1
Select it and click Create

It will ask to ReStage, say YES

hit the back arrow on the top left
You will now see Services has 2

Click Services and click Text to Speech
click Service Credentials on the left
click add Credentials on the right
name it serviceTESTApp1-TTS (whatever you want or just leave the default…)

Now you will see your credentials, you need these for the app

Open a notepad session on Windows or Notes session on Mac and copy all of this block of text you will need this for the android app

{
"credentials": {
"url": "https://stream.watsonplatform.net/text-to-speech/api",
"username": “yyyyyyyyyyyy”,
"password": “wwwwwwwww”
}
}

Now lets test your credentials before we move on
take the url above they are different
"url": "https://stream.watsonplatform.net/text-to-speech/api",
copy and paste the https…./api in your browser and use the user name and password blue mix provided you above

You will know you got in it will say invalid credentials if it didn’t work and if it did work you will see a JSON output and documentation recommendations…

Now we are done with Bluemix

go here and download the android SDK ( which you probably already have… )

https://github.com/watson-developer-cloud/speech-android-sdk

click download zip on top right

unzip and in the folder you will see 2 folders, 2 project and a grade folder

Open Android Studio
Click open an existing project
Select the folder you just downloaded with all the 3 folders and files in it…
or
Click File > Open > and Select the folder you just downloaded with all the 3 folders and files in it…

Now lets set the credentials we just tested in place

Click on Project on the left side of the window if you don’t see any folders or code…

go to Examples > res > values > strings.xml

where you see default credentials… delete that block and replace with below….




<!-- 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>


Now fill in the URL for Token Factory , Username , and password you received

We are done with this file

Now open Example project > Java > com….. > MainActivity

find this method initSTT comment out don’t delete it… then copy and paste this version of the method

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

find this method initTTS comment out don’t delete it… then copy and paste this version of the method

 private boolean initTTS() {
     String username = getString(R.string.TTSdefaultUsername);
     String password = getString(R.string.TTSdefaultPassword);
     String tokenFactoryURL = getString(R.string.TTSdefaultTokenFactory);
     String serviceURL = "https://stream.watsonplatform.net/text-to-speech/api";
     TextToSpeech.sharedInstance().initWithContext(this.getHost(serviceURL));
     TextToSpeech.sharedInstance().setCredentials(username, password);
     TextToSpeech.sharedInstance().setVoice(getString(R.string.voiceDefault));
     return true;
 }

We are done with this file

Now run the app on a test device

If you see any please check internet connection messages, that simply means your credentials are not working. Test them again on your browser and also make sure the URLs for Speech to Text and Text to Speech are correct they are different urls and the credentials will NOT work on both

Now from this point if anyone has any resources on how to make the REST speech to text services work with Android please reply or message me so we can collaborate.

thanks

@mis101bird
Copy link

@KeyOnTech Thanks~Help me a lot

@germanattanasio
Copy link
Contributor

@jzhang300 can you please update the readme with the instructions that @KeyOnTech wrote?

@germanattanasio
Copy link
Contributor

maybe it's time to learn some android 🐤

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants