• Like
  • Save
MobiCom on Android: Design & Consumption of Services, TTS Basics
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

MobiCom on Android: Design & Consumption of Services, TTS Basics

  • 2,934 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,934
On SlideShare
0
From Embeds
0
Number of Embeds
45

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. MobiCom on AndroidDesign & Consumption ofServices, TTS Basicswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedcoVladimir Kulyukin
  • 2. Outline●Design & Consumption of Services– Started Services– Intent Services– HTTP Services●TTS Basicswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 3. Tasks & Serviceswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 4. Three Thread Rules●Remember that Android UI widgets arenot thread-safe●Do not block the Main Thread (aka the UIthread)●Do not access UI widgets from outsidethe UI threadwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 5. Long Running Tasks●If Android can kill any application at any time,how can one do long running tasks?●Enter services●A Service is a way for an application to requestAndroid to keep it running for a while●If there is not enough RAM, Android may stillterminate services●Services may negotiate non-stop status throughnotificationswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 6. What is a Service?●A Service is an application component forperforming long running operations in thebackground●Services have no user interfaces, and are startedby other application components●Services may continue to run in the backgroundeven after the user switches to anotherapplication different from the application thatstarted themwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 7. What Are Services For?●Services have four primary areas of use:– Network transactions– Intensive I/O– Interaction with content providers– Multimedia operations (e.g., playingmusic)www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 8. Two Types of Services●There are two types of services in theAndroid Ecosystem: started (aka local) andbound (aka remote)●Started services are used within oneapplication●Bound services are used for inter-processcommunication (IPC) that goes acrossapplication boundarieswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 9. Started Services●A Started service is started by an application component(typically, an activity) that calls startService()●Once started, a service may run in the backgroundindefinitely even after the component that started it isdestroyed●A Started service usually performs a single operation thatdoes not return any result to the caller directly●The results are returned to the caller indirectly: a messageon the status bar, saved file, updated content provider, etc●After its work is done, a started service should stop itselfwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 10. Bound Services●A Service is bound when an applicationcomponent binds to it by calling bindService()●A Bound service offers a client-server interfacethat components can use to interact with theservice, send requests, receive results, and doother IPC stuff●Bound services offer the same type offunctionality as remote method invocation (RMI)in Javawww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 11. Bound Services●Multiple components can bind to a boundservice at once●A Bound service is alive as long as at leastone component is bound to it●When a bound service has no boundcomponents, it is destroyed by Androidwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 12. Services & Threads●Services run in the main thread of their hostingprocesses & do not spawn their own threads unlessexplicitly told to do so●What it means is that if you have a service doing a lot ofCPU-intensive and/or blocking work (networking, playingmusic, I/O), the service may cause its hosting applicationto become non-responsive: this is the infamousApplication Not Responding (ANR) Errorwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 13. START_STICKY vs START_NOT_STICKY●These codes are used when the mobile deviceruns out of memory and kills the started service●When a service is started with START_STICKY,Android re-creates it when it has enough memory●When a service is started withSTART_NOT_STICKY, Android does not bother tore-create it after it kills itwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 14. Started Serviceswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 15. ProblemWrite an application that uses a startedservice to compute all Catalan numbers lessthan or equal to 100,000 and displays themone by one in the status bar.www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedcosource code is here
  • 16. Catalan Numbers●Catalan numbers are a sequence of natural numbers●The numbers get their name after Eugene CharlesCatalan, a 19thcentury Belgian mathematician●Catalan numbers figure prominently in combinatoricsand recursive definitions●Here are a few initial members of the Catalan sequencesfor n = 0, 1, 2, 3●1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796,58786, ...www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 17. Catalan Numbers: Two Interpretations●One interpretation of Catalan numbers is thenumber of binary trees with n nodes: C(0) = 1,C(1) = 1, C(2) = 2, C(3) = 5NULLN = 1N = 0 N = 2 N = 3●Another interpretation is the number ofexpressions with n pairs of parentheses properlymatchedwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 18. Catalan Number Formula( )nn CnnCC2122110++==+www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 19. Solution●Extend the Service class●In the extended class (CatalanNumberService),define a NotificationManager member●In the extended class, define a worker thread class(CatalanServiceWorker) that implements theRunnable interfacewww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 20. Solution●The worker thread and NotificationManagerobjects are created and in onCreate()●The worker thread is also started in onCreate()●Place ornament_00.png (the notification item tobe displayed in the status bar) in /res/drawable-hdpi●Declare the service in AndroidManifest.xmlwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 21. Source Code Highlightswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 22. Binding a ServiceButton btnBindService = (Button)findViewById(R.id.btnStartService);btnBindService.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {startService(newIntent(StartedCatalanServiceAct.this.getApplicationContext(),CatalanNumberService.class));}});www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 23. Unbinding a ServiceButton btnUnbindService = (Button)findViewById(R.id.btnStopService);btnUnbindService.setOnClickListener(new OnClickListener() {public void onClick(View v) {boolean rslt = stopService(new Intent(StartedCatalanServiceAct.this.getApplicationContext(),CatalanNumberService.class));Toast.makeText(StartedCatalanServiceAct.this.getApplicationContext(),"stopService() == " + rslt, Toast.LENGTH_LONG).show();}});www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 24. Spawning Threads from Servicesclass CatalanServiceWorker implements Runnable {public void run() {long n = 0L;while ( mPrevCatNum <= mUpperBound ) {mMsg = ""; mMsg += ("C(" + n + ")=" + mPrevCatNum);CatalanNumberService.this.handleNotificationMessage(mMsg);// Go to sleep to simulate a time-consuming computationtry { Thread.sleep(mSleepInterval); }catch ( Exception ex ) {// Stop the service in case of exceptionCatalanNumberService.this.stopSelf();}nextC(++n);}}}www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 25. Spawning Threads from Services// Get a NotificationManager object from AndroidmNoteMngr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);// Post a message on the status bar that the service has been startedhandleNotificationMessage("starting background catalan service");// Create and start a worker thread.Thread thr = new Thread(null, new CatalanServiceWorker(),"CatalanNumberService");thr.start();www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 26. Posting NotificationsNotification note = new Notification(R.drawable.ornament_00, msg,System.currentTimeMillis());PendingIntent pi = PendingIntent.getActivity(getApplicationContext(),0, new Intent(getApplicationContext(),StartedCatalanServiceAct.class), 0);note.setLatestEventInfo(getApplicationContext(), "Catalan Number Service",msg, pi);this.mNoteMngr.notify(R.string.app_id, note);www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 27. Destroying Services// Post a notification message in the status barhandleNotificationMessage("stopping background catalan service");// Stop the servicestopSelf();// Remove icon from the status barmNoteMngr.cancel(R.string.app_id);// wait a second to make sure that the message has a chance// to show on the status barsynchronized (this ) { try { wait(1000); } catch ( Exception ex ) {}}// If you uncomment the following line, the hosting process is killed.// Process.killProcess(Process.myPid());www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 28. Declaring Services in AndroidManifest.xml<applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name" ><activityandroid:label="@string/app_name"android:name=".StartedCatalanServiceAct" ><intent-filter ><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><service android:name="CatalanNumberService" /></application>www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 29. Observations on StartedCatalanService●If a component starts the service by callingstartService() (which results in a call toonStartCommand()), then the service remains runninguntil it stops itself with stopSelf() or another componentstops it by calling stopService()●Even when stopService() is called, Runnable objects donot appear to be stopped until Android callsonDestroy()●Be careful about using the status bar, especially puttingdrawables in there, unless you are reasonably certainthat the user will not mindwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 30. Intent Serviceswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 31. Alternatives to Multi-Threading●What if you do not want to live dangerously?●Suppose that you do not need multi-threading●Suppose your application needs to handleone background request at a time●Are there safer alternatives to creating andmanaging worker threads?●The answer is – yes, it is IntentServicewww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 32. What is IntentService?●IntentService is a subclass of Service●IntentService handles all start requestsone at a time●IntentService is the best option if multi-threading is not needed●All one needs to do is to implementonHandleIntent() which receives theintent for each start requestwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 33. What Does IntentService Do?●Creates a worker thread that executes all intentsgiven to onStartCommand()●The worker thread is different from yourapplications main thread●Creates a work queue that passes one intent at atime to onHandleIntent(): no multi-threading isguaranteed●Stops the service after all start intents have beenprocessed: no need to call stopSelf()www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 34. What Does IntentService Do?●Provides a default implementation of onBind()that returns null●Provides a default implementation ofonStartCommand() that puts intents to thework queue and then to onHandleIntent()●What do you need to do if you want to useIntentService:– Implement onHandleIntent()– Implement a constructor for the servicewww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 35. ProblemWrite an application that uses anIntentService to compute the sum of thefirst n members of the Catalan sequencesand the Fibonacci sequence; the sequenceis selected by the user.www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedcosource code is here
  • 36. Screenshotswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco1 2 3 4
  • 37. Source Code Highlightswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 38. StartedSumIntentService.javaprotected void onHandleIntent(Intent intent) {Bundle extras = intent.getExtras(); String catSumKey = mRes.getString(R.string.cat_sum);String fibSumKey = mRes.getString(R.string.fib_sum); String nKey = mRes.getString(R.string.n_key);// 1. check if the bundle contains cat_sum or fib_sum key and n_keyif ( (extras.containsKey(catSumKey) || extras.containsKey(fibSumKey)) && extras.containsKey(nKey) ) {long n = extras.getLong(nKey);// 2. if cat_sum key is present, then compute the catalan sum and post a notification message// on the status barif ( extras.containsKey(catSumKey) ) { postNotificationMessage(compileCatNote(n, catalanSum(n))); }else {// 3. if fibo_sum key is present, then compute the fibonacci sum and post a notification message on// the status barpostNotificationMessage(compileFiboNote(n, fiboSum(n)));}}else { postNotificationMessage("Wrong arguments"); }mNoteMngr.cancel(R.string.app_id); }www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 39. StartedSumIntentServiceAct.java// 1. Create an Intent to run StartedSumIntentService.classIntent i1 = new Intent(getApplicationContext(), StartedSumIntentService.class);long n1 = Long.parseLong(mNEdtTxt.getText().toString().toString());// 2. Put two key-value pairs (<cat_sum, true> and <n, n1>) into the Intents bundlei1.putExtra(mRes.getString(R.string.cat_sum), true);i1.putExtra(mRes.getString(R.string.n_key), n1);// 3. start service with the created intentstartService(i1);www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 40. StartedSumIntentServiceAct.java// 1. Create an Intent to run StartedSumIntentService.classIntent i1 = new Intent(getApplicationContext(), StartedSumIntentService.class);long n1 = Long.parseLong(mNEdtTxt.getText().toString().toString());// 2. Put two key-value pairs (<cat_sum, true> and <n, n1>) into the Intents bundlei1.putExtra(mRes.getString(R.string.cat_sum), true);i1.putExtra(mRes.getString(R.string.n_key), n1);// 3. start service with the created intentstartService(i1);www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 41. Consumption of HTTP Serviceswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 42. Consuming HTTP Services●HTTP Services are the most frequently consumed services onAndroid●You can use either GET or POST methods●Steps of consuming HTTP services:– Create an HttpClient– Create an Http method– Execute the request– Convert the response to String with BufferedReader– Try executing the request several times– Do it in a background service if HTML parsing is time-consumingwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 43. HTTP Consumption: Useful Classes●HttpParams – collection of HTTP protocol andframework parameters●Scheme – a specific protocol scheme, such as http orhttps●SchemeRegistry – a set of supported protocol schemes●ClientConnectionManager – interface for managingclient connections●ThreadSafeClientConnManager – class for managinga pool of safe client connectionswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 44. ProblemWrite an application that uses the GETmethod to obtain the source of a user-specified URL and returns it as a string.www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedcosource code is here
  • 45. Screenshots1) start screen 2) url input 3) url sourcewww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 46. Source Code Highlightswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 47. Get URLs Sourcewww.youtube.com/vkedcowww.youtube.com/vkedco www.vkedco.blogspot.comwww.vkedco.blogspot.comBufferedReader in = null;HttpClient hc = new DefaultHttpClient(); // 1. Construct an http clientHttpGet req = new HttpGet(); // 2. Construct a get requestreq.setURI(uri); // 3. specify the uri of the requestHttpResponse res = hc.execute(req); // 4. execute the request// 5. open a buffered reader to the requests content & readin = new BufferedReader(new InputStreamReader(res.getEntity().getContent()));StringBuffer sb = new StringBuffer("");String currLine = "";String LNSPRTR = System.getProperty("line.separator");while ( (currLine = in.readLine()) != null ) { sb.append(currLine + LNSPRTR); }in.close();return sb.toString();
  • 48. Sharing Consumed HTTP Results●Is there a way to share consumed HTTP results with otheractivities within the same application?●You can extend the Application class●Application class is a singleton●You can create a member variable in your extension●Activities can use that member variable as shared memory●You have to do synchronization●You have to provide for the case of application shutdown– Override your extensions onLowMemory()– Make activities more robustwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 49. ProblemModify the previous application that usesthe GET method to obtain the source of auser-specified URL and returns it as a stringso that it can share the string with otheractivities.www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedcosource code is here
  • 50. Text to Speech Basicswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 51. PICO●Pico is an Android multi-lingual speechsynthesis language●Pico can be used as a black box: text in,speech out●Pico is the only TTS engine on thedevicewww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 52. TTS Sharing●TTS engine is shared among allactivities on the device●It is never a certainty that the text isspoken and, if it is, when it is spoken●The only way to find out what is goingon is to use the TTS callback methodswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 53. Starting TTS●It is best practice to check if TTS is availableon the device●This is done via Intent to check TTS data●If the check is successful, a instance of TTScan be created●Activity that uses TTS implementsOnInitListener interfacewww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 54. Checking TTS Availability●In Activity.onCreate():Intent ttsi = new Intent();ttsi.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);startActivityForResult(ttsi, CHECK_TTS_REQ);www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 55. Creating TTS Instance●In Activitys onActivityResult():switch ( result_code ) {caseTextToSpeech.Engine.CHECK_VOICE_DATA_PASS:mTTS = new TextToSpeech(this, this);break;}www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 56. Handling Missing TTS Data●In Activitys onActivityResult():switch ( result_code ) {case TextToSpeech.Engine.CHECK_VOICE_BAD_DATA:case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_DATA:case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_VOLUME:Intent insti = new Intent();insti.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);startActivity(insti);}www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 57. Handling TTS Unavailability●In Activitys onActivityResult():switch ( result_code ) {case TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL:// Let the user know that TTS is not available – Toast, LogMessage, Notification, etc.}www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 58. What To Do When TTS Is Ready●Override Activitys onInit():@Overridepublic void onInit(int status) {if ( status == TextToSpeech.SUCCESS ) {// do something when you know that TTS isavailable}}www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 59. Overriding onPause() and onDestroy()●When your Activity is paused (e.g., it losesfocus), have TTS stop synthesizing●When your Activity is destroyed, shut TTSdown to notify Android that the resourcescan be released and given to otheractivities or applicationswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 60. Overriding onPause() and onDestroy()public void onPause() {super.onPause();if ( mTTS != null ) mTTS.stop();}www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 61. Overriding onPause() and onDestroy()public void onDestroy() {super.onPause();if ( mTTS != null ) mTTS.shutdown();}www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 62. ProblemWrite an application that allows the user towrite a string and TTS it.www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedcosource code is here
  • 63. Screenshotswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 64. Source Code Highlightswww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 65. SimpleTTSDemoAct.javawww.youtube.com/vkedcowww.youtube.com/vkedco www.vkedco.blogspot.comwww.vkedco.blogspot.comprivate HashMap<String, String> mTtsParams = new HashMap<String, String>();mBtnSpeak = (Button) findViewById(R.id.speak);mBtnSpeak.setOnClickListener(new OnClickListener() {public void onClick(View view) {StringTokenizer st = new StringTokenizer(mWordsToSpeak.getText().toString(), ",.");while ( st.hasMoreTokens() ) {mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,String.valueOf(mUttCount++));String tok = st.nextToken();mTts.speak(tok, TextToSpeech.QUEUE_ADD, mTtsParams);}}});
  • 66. Words Outside of TTS Model●What happens if you need to TTS wordsthat are outside of your TTS model?– Create your own TTS model (possiblebut difficult)– Create your own custom spelling of aword, generate a wav file, andassociate it with a wordwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 67. How About TTSing This?www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 68. Bhagavat Gita Verse 01www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 69. Sanskrit in Latin Transliterationdharmakshetre kurukshetre samaveta yuyutsavahmamakah pandavashcaiva kim akurvata samjayawww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 70. English TranslationOh, Sanjaya, tell me what happened atKurukshetra, the field of dharma, where myfamily and the Pandavas gathered to fight?Translated by Eknath Easwaranwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 71. Russian TranslationЧто свершили, - скажи Санджая, -сыновья мои и Пандавы,ради битвы сойдясь на полеКурукшетры, на поле дхармы?Translated by V.S. Semenstsovwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 72. ProblemWrite an application that TTSes the firstverse of Bhagavat Gita in Sanskrit,Russian, and English.www.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedcosource code is here
  • 73. Screenshotwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco
  • 74. Reading Suggestions●http://developer.android.com/resources/articles/multitasking-android-way.html●http://en.wikipedia.org/wiki/Catalan_number●http://www.sanskritweb.net/sansdocs/gita-big.pdf●www.bhagavatgita.ruwww.vkedco.blogspot.comwww.vkedco.blogspot.comwww.youtube.com/vkedcowww.youtube.com/vkedco