コード例 #1
0
  private void doFinalInitialization() {

    if (null == myTTS.getLanguage()) {
      setActionsEnabled(false);
      showErrorMessage(getText(R.string.no_tts_language), true);
      return;
    }

    myTTS.setOnUtteranceCompletedListener(this);

    myTTS.addEarcon(CONTENTS_EARCON, "org.benetech.android", R.raw.sound_toc);
    myTTS.addEarcon(MENU_EARCON, "org.benetech.android", R.raw.sound_main_menu);
    myTTS.addEarcon(FORWARD_EARCON, "org.benetech.android", R.raw.sound_forward);
    myTTS.addEarcon(BACK_EARCON, "org.benetech.android", R.raw.sound_back);
    myTTS.addEarcon(START_READING_EARCON, "org.benetech.android", R.raw.sound_start_reading);

    setCurrentLocation();

    myTTS.playEarcon(START_READING_EARCON, TextToSpeech.QUEUE_ADD, null);

    if (accessibilityManager.isEnabled()) {
      speakString(myApi.getBookTitle(), 0);
    } else {
      setTitle(myApi.getBookTitle());
    }

    setActionsEnabled(true);
    speakParagraph(getNextParagraph());
  }
コード例 #2
0
ファイル: JaneService.java プロジェクト: willwhitney/jane
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    instance = this;
    Log.i("Jane", "Received start id " + startId + ": " + intent);
    Log.d("Jane", "Service received start command.");

    tts =
        new TextToSpeech(
            this,
            new TextToSpeech.OnInitListener() {

              @Override
              public void onInit(int status) {}
            });
    tts.setOnUtteranceCompletedListener(this);

    // set up Bluetooth here
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      bt = new Gingerbread();
    } else {
      bt = new Honeycomb();
    }

    bt.setContext(getApplicationContext());

    try {
      bt.getProxy();
    } catch (Exception e) {
      e.printStackTrace();
    }

    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    ComponentName mediaButtonResponder =
        new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    am.registerMediaButtonEventReceiver(mediaButtonResponder);

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WakeLock lock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "JaneLock");
    lock.acquire(10 * 60 * 1000);

    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localChatReceiver = new ChatReceiver(this);

    String username = intent.getExtras().getString("username");
    String password = intent.getExtras().getString("password");
    uiMessenger = intent.getExtras().getParcelable("messenger");

    nameCache = new HashMap<String, String>();
    chatCache = new HashMap<String, Chat>();

    smack = org.jivesoftware.smack.SmackAndroid.init(this);

    this.registerReceiver(stateIntents, new IntentFilter(JaneIntent));
    this.registerReceiver(stateIntents, new IntentFilter(Bluetooth.BLUETOOTH_STATE));

    LoginThread login = new LoginThread(username, password, this);
    login.start();

    return START_STICKY;
  }
コード例 #3
0
  @SuppressWarnings("deprecation")
  public static void setUtteranceCompletedListener(
      TextToSpeech tts, final RUTextToSpeech ruTextToSpeech) {
    if (Build.VERSION.SDK_INT < 15) {
      tts.setOnUtteranceCompletedListener(
          new android.speech.tts.TextToSpeech.OnUtteranceCompletedListener() {
            @Override
            public void onUtteranceCompleted(String utteranceId) {
              ruTextToSpeech.utteranceCompleted(utteranceId);
            }
          });
    } else {
      tts.setOnUtteranceProgressListener(
          new UtteranceProgressListener() {
            @Override
            public void onDone(String utteranceId) {
              ruTextToSpeech.utteranceCompleted(utteranceId);
            }

            @Override
            public void onError(String utteranceId) {
              ruTextToSpeech.utteranceCompleted(utteranceId);
            }

            @Override
            public void onStart(String utteranceId) {}
          });
    }
  }
コード例 #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newlayout);
    myHashAlarm = new HashMap();
    myHashAlarm.put(
        TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
    myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "end of wakeup message ID");

    // mText = (TextView) findViewById(R.id.textView12);

    getWindow().setFormat(PixelFormat.UNKNOWN);
    mVideoView = (VideoView) findViewById(R.id.videoview);
    mVideoView.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer mp) {
            // TODO Auto-generated method stub
            initializeVideo();
          }
        });

    sr = SpeechRecognizer.createSpeechRecognizer(this);
    sr.setRecognitionListener(new listener());
    countDownTimer = new MyCountDownTimer(Constants.startTime, Constants.interval);
    amanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    t1 = new TextToSpeech(this, this);
    t1.setOnUtteranceCompletedListener(this);
    t1.setSpeechRate((float) 0.8); // normal 1
    t1.setPitch((float) 1.8); // normal 1
    initializeVideo();
  }
コード例 #5
0
  private void startSpeech() {
    TextToSpeech tts = SFApplication.get().getTts();

    doSpeech(SFApplication.get().getPrefs().getWeather());

    // Remove the old weather information
    SFApplication.get().getPrefs().setWeather(null);

    // UtteranceProgressListener not available in api < 15

    tts.setOnUtteranceCompletedListener(utteranceListener);
  }
コード例 #6
0
ファイル: AnyMemoTTSImpl.java プロジェクト: joecks/memo
  // We need setOnUtteranceCompletedListener for compatibility with Android 2.x
  @SuppressWarnings("deprecation")
  public void sayText(
      final String s, final OnTextToSpeechCompletedListener onTextToSpeechCompletedListener) {
    /*if there is a user defined audio, speak it and return */
    if (speakWord.speakWord(s)) {
      // This enables auto speak for user defined audio files.
      speakWord.setOnCompletedListener(
          new OnCompletedListener() {

            @Override
            public void onCompleted() {
              if (onTextToSpeechCompletedListener != null) {
                onTextToSpeechCompletedListener.onTextToSpeechCompleted(s);
              }
            }
          });

      return;
    }

    /*otherwise, speak the content*/
    Log.v(TAG, "say it!");
    // This is slightly different from AMStringUtils.stripHTML since we replace the <br> with
    // a period to let it have a short pause.
    // Replace break with period
    String processed_str = s.replaceAll("\\<br\\>", ". ");
    // Remove HTML
    processed_str = processed_str.replaceAll("\\<.*?>", "");
    // Remove () [] and their content
    processed_str = processed_str.replaceAll("\\[.*?\\]", "");
    // Remove the XML special character
    processed_str = processed_str.replaceAll("\\[.*?\\]", "");
    processed_str = processed_str.replaceAll("&.*?;", "");

    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "id");

    myTTS.setOnUtteranceCompletedListener(
        new TextToSpeech.OnUtteranceCompletedListener() {
          @Override
          public void onUtteranceCompleted(String utteranceId) {
            if (onTextToSpeechCompletedListener != null) {
              onTextToSpeechCompletedListener.onTextToSpeechCompleted(s);
            }
          }
        });

    speakLock.lock();

    Log.i(TAG, "processed_str is \"" + processed_str + "\"");
    myTTS.speak(processed_str, 0, params);
    speakLock.unlock();
  }
コード例 #7
0
ファイル: studyWord.java プロジェクト: zinsser/KingSpace
        @Override
        public void onInit(int status) {
          // TODO Auto-generated method stub
          Locale loc = new Locale("uk");
          SharedPreferences setting =
              getSharedPreferences("wordroid.model_preferences", MODE_PRIVATE);
          if (setting.getString("category", "1").equals("2")) loc = new Locale("us");

          /* 检查是否支持输入的时区 */
          if (tts.isLanguageAvailable(loc) == TextToSpeech.LANG_AVAILABLE) {
            /* 设定语言 */
            tts.setLanguage(loc);
          }
          tts.setOnUtteranceCompletedListener(ttsUtteranceCompletedListener);
        }
コード例 #8
0
  @Override
  public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
      // TODO: check if the language is available
      Locale ttsLanguage;
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        ttsLanguage = tts.getDefaultLanguage();
      } else {
        ttsLanguage = tts.getLanguage();
      }

      if (ttsLanguage == null) {
        ttsLanguage = Locale.US;
      }

      int supportStatus = tts.setLanguage(ttsLanguage);
      switch (supportStatus) {
        case TextToSpeech.LANG_MISSING_DATA:
        case TextToSpeech.LANG_NOT_SUPPORTED:
          tts.shutdown();
          tts = null;

          Log.e(TAG, "TTS Language data is not available.");
          Toast.makeText(context, "Unable to set 'Text to Speech' language!", Toast.LENGTH_LONG)
              .show();
          break;
      }

      if (tts != null) {
        tts.setOnUtteranceCompletedListener(mSpeechCompleteListener);
        // Register the broadcast receiver for the speech output period
        // updates
        LocalBroadcastManager.getInstance(context)
            .registerReceiver(
                mSpeechIntervalUpdateReceiver,
                new IntentFilter(SettingsFragment.ACTION_UPDATED_STATUS_PERIOD));
      }
    } else {
      // Notify the user that the tts engine is not available.
      Log.e(TAG, "TextToSpeech initialization failed.");
      Toast.makeText(
              context,
              "Please make sure 'Text to Speech' is enabled in the "
                  + "system accessibility settings.",
              Toast.LENGTH_LONG)
          .show();
    }
  }
コード例 #9
0
ファイル: SayMagicWordDemo.java プロジェクト: rjtatz/android
  /** set the TTS listener to call {@link #onDone(String)} depending on the Build.Version */
  private void setTtsListener() {
    final SayMagicWordDemo callWithResult = this;
    if (Build.VERSION.SDK_INT >= 15) {
      int listenerResult =
          tts.setOnUtteranceProgressListener(
              new UtteranceProgressListener() {
                @Override
                public void onDone(String utteranceId) {
                  callWithResult.onDone(utteranceId);
                }

                @Override
                public void onError(String utteranceId) {
                  Log.e(TAG, "TTS error");
                }

                @Override
                public void onStart(String utteranceId) {
                  Log.d(TAG, "TTS start");
                }
              });
      if (listenerResult != TextToSpeech.SUCCESS) {
        Log.e(TAG, "failed to add utterance progress listener");
      }
    } else {
      int listenerResult =
          tts.setOnUtteranceCompletedListener(
              new OnUtteranceCompletedListener() {
                @Override
                public void onUtteranceCompleted(String utteranceId) {
                  callWithResult.onDone(utteranceId);
                }
              });
      if (listenerResult != TextToSpeech.SUCCESS) {
        Log.e(TAG, "failed to add utterance completed listener");
      }
    }
  }