From 904dfa588431ff7c99c337d7797f5bef9ac12ce3 Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Wed, 15 Jul 2009 10:44:41 -0700 Subject: [PATCH] Adding missing addEarcon method. Not having this was a bug as this method is needed to add earcons; otherwise, there is nothing for playEarcon to play. --- api/current.xml | 32 ++++++ .../java/android/speech/tts/TextToSpeech.java | 103 ++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/api/current.xml b/api/current.xml index 6a5680d69c088..afba8946e8cea 100644 --- a/api/current.xml +++ b/api/current.xml @@ -111074,6 +111074,38 @@ + + + + + + + + + + + + + + "[tick]"
+ * + * @param packagename + * Pass the packagename of the application that contains the + * resource. If the resource is in your own application (this is + * the most common case), then put the packagename of your + * application here.
+ * Example: "com.google.marvin.compass"
+ * The packagename can be found in the AndroidManifest.xml of + * your application. + *

+ * <manifest xmlns:android="..." + * package="com.google.marvin.compass"> + *

+ * + * @param resourceId + * Example: R.raw.tick_snd + * + * @return Code indicating success or failure. See TTS_ERROR and TTS_SUCCESS. + */ + public int addEarcon(String earcon, String packagename, int resourceId) { + synchronized(mStartLock) { + if (!mStarted) { + return TTS_ERROR; + } + try { + mITts.addEarcon(mPackageName, earcon, packagename, resourceId); + return TTS_SUCCESS; + } catch (RemoteException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - addEarcon", "RemoteException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } catch (NullPointerException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - addEarcon", "NullPointerException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } catch (IllegalStateException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - addEarcon", "IllegalStateException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } + return TTS_ERROR; + } + } + + + /** + * Adds a mapping between a string of text and a sound file. Using this, it + * is possible to add custom earcons. + * + * @param earcon + * The name of the earcon + * @param filename + * The full path to the sound file (for example: + * "/sdcard/mysounds/tick.wav") + * + * @return Code indicating success or failure. See TTS_ERROR and TTS_SUCCESS. + */ + public int addEarcon(String earcon, String filename) { + synchronized (mStartLock) { + if (!mStarted) { + return TTS_ERROR; + } + try { + mITts.addEarconFile(mPackageName, earcon, filename); + return TTS_SUCCESS; + } catch (RemoteException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - addEarcon", "RemoteException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } catch (NullPointerException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - addEarcon", "NullPointerException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } catch (IllegalStateException e) { + // TTS died; restart it. + Log.e("TextToSpeech.java - addEarcon", "IllegalStateException"); + e.printStackTrace(); + mStarted = false; + initTts(); + } + return TTS_ERROR; + } + } + + /** * Speaks the string using the specified queuing strategy and speech * parameters. Note that the speech parameters are not universally supported