[android-developers] Re: Text To Speech Android 1.6 with minsdk 3
Thanks, glad you posted this! I used your WrapTTS class exactly as
you have it, but nfortunately, running it on the 1.5 emulator still
crashes (works great on 1.6 though).
Just doing what you did above, declaring the 2 global variables and
doing the checkAvailable() check, but the app force closes as soon as
the activity starts. Below are the errors I am getting in LogCat
pertaining to this. Any ideas?
LogCat:
12-19 13:33:24.507: INFO/dalvikvm(953): Failed resolving Lme/myApp/
WrapTTS; interface 42 'Landroid/speech/tts/TextToSpeech
$OnInitListener;'
12-19 13:33:24.587: WARN/dalvikvm(953): Link of class 'Lme/myApp/
WrapTTS;' failed
12-19 13:33:24.597: ERROR/dalvikvm(953): Could not find method
me.myApp.WrapTTS.checkAvailable, referenced from method
me.myApp.DisplayStory.<clinit>
12-19 13:33:24.647: WARN/dalvikvm(953): VFY: unable to resolve static
method 562: Lme/myApp/WrapTTS;.checkAvailable ()V
12-19 13:33:24.647: WARN/dalvikvm(953): VFY: rejecting opcode 0x71 at
0x0020
On Nov 18, 4:48 pm, Eric Carman <ewcarma...@gmail.com> wrote:
> Hello,
>
> I was playing with addingTexttoSpeechto one of my applications and
> have been working with it using the Android1.6SDK. I was hoping to
> release the code such that it could be used on the earlier1.5OS
> since there are still quite a few of these around - and this is an
> upgrade. I realize that the TTS won't work on the1.5(at least not as
> I have it here), but I didn't want the app disappearing from the
> market for those devices.
>
> At any rate, after struggling for a while with this - a lot of trial
> and error - I came up with what now seems like a simple wrapper to
> allow for the backward compatibility. This was mostly taken from the
> Android blog entry
>
> http://android-developers.blogspot.com/2009/04/backward-compatibility...
>
> so I'm not exactly breaking new ground. Also, I'm not using all of the
> TTS features, hence the short list of "wrapped" methods, expand at
> your leisure. I'm attaching it here for anyone to use and anyone to
> comment on if I have done something really stupid. I'll comment back
> if my testing uncovers anything untoward.
>
> Wrapper Class:
>
> package com.mydomain.myapp;
>
> import java.util.HashMap;
> import java.util.Locale;
>
> import android.content.Context;
> import android.speech.tts.TextToSpeech;
>
> public class WrapTTS {
>
> private TextToSpeech mTTS;
>
> /* class initialization fails when this throws an exception */
> static {
> try {
> Class.forName("android.speech.tts.TextToSpeech");
> } catch (Exception ex) {
> throw new RuntimeException(ex);
> }
> }
>
> /* calling here forces class initialization */
> public static void checkAvailable() {}
>
> private OnInitListener onInitListener = null;
> public interface OnInitListener {
> public abstract void onInit(int status);
> }
>
> public WrapTTS(Context context, WrapTTS.OnInitListener listener) {
> onInitListener = listener;
> mTTS = new TextToSpeech(context,
> new TextToSpeech.OnInitListener() {
>
> @Override
> public void onInit(int status) {
> onInitListener.onInit(status);
> }
>
> });
>
> }
>
> public int setSpeechRate(float speechRate) {
> return mTTS.setSpeechRate(speechRate);
> }
>
> public void shutdown() {
> mTTS.shutdown();
> }
>
> public int speak(Stringtext, int queueMode, HashMap<String, String>
> params) {
> return mTTS.speak(text, queueMode, params);
> }
>
> public int setLanguage(Locale loc) {
> return mTTS.setLanguage(loc);
> }
>
> public int isLanguageAvailable(Locale loc) {
> return mTTS.isLanguageAvailable(loc);
> }
>
> }
>
> The following is used at the top of my main application.
>
> private WrapTTS mTts = null;
> private static boolean mTTSClassAvailable = false;
>
> /* establish whether the "TextToSpeech" class is available to us */
>
> static {
> try {
> WrapTTS.checkAvailable();
> mTTSClassAvailable = true;
> } catch (Throwable t) {
> mTTSClassAvailable = false;
> }
> }
>
> Use the mTTSClassAvailable to know whether to bother to even try to
> set up the engine.
>
> Hopefully it helps someone.
>
> Best Regards,
> Eric
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home