Created
November 1, 2016 17:13
-
-
Save hbcafe/124c157db725ce6ad521c4e40343c0b2 to your computer and use it in GitHub Desktop.
Connect native Android app to Watson Text to Speech in under 10 minutes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ibm.watsonvoicetts; | |
import android.os.AsyncTask; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
TextView textView; | |
EditText editText; | |
Button button; | |
private class WatsonTask extends AsyncTask<String, Void, String> { | |
@Override | |
protected String doInBackground(String... textToSpeak) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
textView.setText("running the Watson thread"); | |
} | |
}); | |
return "text to speech done"; | |
} | |
@Override | |
protected void onPostExecute(String result) { | |
textView.setText("TTS status: " + result); | |
} | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
editText = (EditText) findViewById(R.id.editText); | |
button = (Button) findViewById(R.id.button); | |
textView = (TextView) findViewById(R.id.textView); | |
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
System.out.println("the text to speech: " + editText.getText()); | |
textView.setText("TTS: " + editText.getText()); | |
WatsonTask task = new WatsonTask(); | |
task.execute(new String[]{}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment