PageRenderTime 32ms CodeModel.GetById 21ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/tts/src/com/google/tts/MakeBagel.java

http://eyes-free.googlecode.com/
Java | 66 lines | 56 code | 10 blank | 0 comment | 8 complexity | 694ea2254439be96ebd56a3c6adec626 MD5 | raw file
 1package com.google.tts;
 2
 3import com.google.tts.TTS.InitListener;
 4import com.google.tts.TTS.SpeechCompletedListener;
 5
 6import java.util.Locale;
 7
 8import android.app.Activity;
 9import android.util.Log;
10
11
12public class MakeBagel extends Activity {
13  private TTS mTts;
14  private String message;
15  private String langRegionString;
16  private MakeBagel self;
17
18  SpeechCompletedListener completionListener = new SpeechCompletedListener() {
19    public void onSpeechCompleted() {
20      mTts.shutdown();
21      self.setResult(Activity.RESULT_OK);
22      finish();
23    }
24  };
25
26  @Override
27  protected void onResume() {
28    super.onResume();
29    self = this;
30    self.setResult(Activity.RESULT_CANCELED);
31    message = this.getIntent().getStringExtra("message");
32    String language = this.getIntent().getStringExtra("language") + "";
33    String country = this.getIntent().getStringExtra("country") + "";
34    String variant = this.getIntent().getStringExtra("variant") + "";
35    Locale loc = new Locale(language, country, variant);
36    language = loc.getISO3Language();
37    country = loc.getISO3Country();
38    langRegionString = "";
39    if (language.length() == 3) {
40      if (country.length() == 3) {
41        langRegionString = language + "-" + country;
42      } else {
43        langRegionString = language;
44      }
45    }
46
47    mTts = new TTS(this, new InitListener() {
48      public void onInit(int status) {
49        mTts.setOnSpeechCompletedListener(completionListener);
50        if (langRegionString.length() > 0) {
51          mTts.setLanguage(langRegionString);
52        }
53        mTts.speak(message, 0, null);
54      }
55    }, true);
56  }
57
58  @Override
59  protected void onDestroy() {
60    super.onDestroy();
61    if (mTts != null) {
62      mTts.shutdown();
63    }
64  }
65
66}