/*
   * Code to run ONCE after the driver hits STOP
   */
  @Override
  public void stop() {

    //  add function to clean up status of robot
    textToSpeech.stop();
    textToSpeech.shutdown();
  }
  private void decideDirection(ArrayList<String> matches) {
    int position = -1;

    for (String phrase : matches) {

      position = commands.indexOf(phrase.toLowerCase());
      if (position != -1) {
        break;
      }
    }

    if (position != -1) {
      Utilities.setDirectionImage(commands.get(position).toUpperCase(), ivDirection, bt);
      textToSpeech.speak(
          "EXECUTING COMMAND " + commands.get(position).toUpperCase(),
          TextToSpeech.QUEUE_FLUSH,
          null);
      ((TextView) findViewById(R.id.tvResults)).setText(commands.get(position).toUpperCase());
      command = commands.get(position).toUpperCase();
    } else {
      Utilities.setDirectionImage("STOP", ivDirection, bt);
      textToSpeech.speak("NO COMMAND DETECTED STOPPING", TextToSpeech.QUEUE_FLUSH, null);
      ((TextView) findViewById(R.id.tvResults)).setText("STOP");
      command = "STOP";
    }
  }
示例#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 boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_pt_br) {
      Locale locale = new Locale("pt", "BR");
      tts.setLanguage(locale);
      return true;
    } else if (id == R.id.action_en_us) {
      Locale locale = Locale.ENGLISH;
      tts.setLanguage(locale);
      return true;
    } else if (id == R.id.action_check_data) {
      // Verifica se o pacote de dados do TTS está instalado
      Intent checkIntent = new Intent();
      checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
      startActivityForResult(checkIntent, ACTION_CHECK_DATA_CODE);
      return true;
    } else if (id == R.id.action_install_data) {
      // Instala o pacote de dados
      Intent installIntent = new Intent();
      installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
      startActivity(installIntent);
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
  @Override
  public void onInit(int status) {
    int result;
    if (status == TextToSpeech.SUCCESS) {
      Locale[] AvalLoc = Locale.getAvailableLocales();

      Log.i("TTS", "Available locales " + Arrays.toString(AvalLoc));

      Locale pol_loc = new Locale("en", "EN");
      if (TextToSpeech.LANG_AVAILABLE == tts.isLanguageAvailable(pol_loc)) {
        result = tts.setLanguage(pol_loc);
      } else {
        result = tts.setLanguage(Locale.ITALIAN);
      }

      if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
        Log.e("TTS", "LANG_NOT_SUPPORTED");
      } else {
        btnSpeak.setEnabled(true);
        speakOut();
      }

    } else {
      Log.e("TTS", "Initialization Failed");
    }
  }
  /**
   * Note: we enforce that this method is called on the UI thread, so we can call
   * nativeVoicesChanged directly.
   */
  private void initialize() {
    assert mNativeTtsPlatformImplAndroid != 0;

    // Note: Android supports multiple speech engines, but querying the
    // metadata about all of them is expensive. So we deliberately only
    // support the default speech engine, and expose the different
    // supported languages for the default engine as different voices.
    String defaultEngineName = mTextToSpeech.getDefaultEngine();
    String engineLabel = defaultEngineName;
    for (TextToSpeech.EngineInfo info : mTextToSpeech.getEngines()) {
      if (info.name.equals(defaultEngineName)) engineLabel = info.label;
    }
    Locale[] locales = Locale.getAvailableLocales();
    mVoices = new ArrayList<TtsVoice>();
    for (int i = 0; i < locales.length; ++i) {
      if (!locales[i].getVariant().isEmpty()) continue;
      if (mTextToSpeech.isLanguageAvailable(locales[i]) > 0) {
        String name = locales[i].getDisplayLanguage();
        if (!locales[i].getCountry().isEmpty()) {
          name += " " + locales[i].getDisplayCountry();
        }
        TtsVoice voice = new TtsVoice(name, locales[i].toString());
        mVoices.add(voice);
      }
    }

    mInitialized = true;
    nativeVoicesChanged(mNativeTtsPlatformImplAndroid);
  }
示例#7
0
 public void destory() {
   if (mTTS != null) {
     mTTS.stop();
     mTTS.shutdown();
     mTTS = null;
   }
 }
示例#8
0
 public void onPause() {
   if (t1 != null) {
     t1.stop();
     t1.shutdown();
   }
   super.onPause();
 }
 private void handleClick(int index) {
   String text = ESLPhrases.get(index);
   if (ttsLoaded) {
     tts.setSpeechRate(0.6f);
     tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
   }
 }
示例#10
0
 @Override
 public void handleMessage(Message message) {
   switch (message.what) {
     case WHAT_SPEAK:
       String utterance = (String) message.obj;
       mTts.speak(utterance, QUEUING_MODE_INTERRUPT, null);
       return;
     case WHAT_STOP_SPEAK:
       mTts.stop();
       return;
     case WHAT_START_TTS:
       mTts =
           new TextToSpeech(
               mContext,
               new TextToSpeech.OnInitListener() {
                 @Override
                 public void onInit(int status) {
                   // register here since to add earcons the TTS must be initialized
                   // the receiver is called immediately with the current ringer mode
                   registerBroadCastReceiver();
                 }
               });
       return;
     case WHAT_SHUTDOWN_TTS:
       mTts.shutdown();
       return;
     case WHAT_PLAY_EARCON:
       int resourceId = message.arg1;
       playEarcon(resourceId);
       return;
     case WHAT_STOP_PLAY_EARCON:
       mTts.stop();
       return;
   }
 }
  @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();
  }
 @Override
 protected void onDestroy() {
   if (tts != null) {
     tts.stop();
     tts.shutdown();
   }
   super.onDestroy();
 }
  public void onDestroy() {
    if (textTalker != null) {
      textTalker.stop();
      textTalker.shutdown();
    }

    super.onDestroy();
  }
 @Override
 public void onDestroy() {
   if (tts != null) {
     tts.stop();
     tts.shutdown();
   }
   super.onDestroy();
 }
 @Override
 public void onDestroy() {
   if (textToSpeech != null) {
     textToSpeech.stop();
     textToSpeech.shutdown();
   }
   super.onDestroy();
 }
 /*
  * (non-Javadoc)
  * @see android.app.Activity#onDestroy()
  */
 @Override
 public void onDestroy() {
   super.onDestroy();
   if (speech != null) {
     speech.stop();
     speech.shutdown();
   }
 }
 @Override
 public void onCallStateChanged(int state, String incomingNumber) {
   speechAllowed = state == TelephonyManager.CALL_STATE_IDLE;
   if (!speechAllowed && tts != null && tts.isSpeaking()) {
     // If we're already speaking, stop it.
     tts.stop();
   }
 }
示例#18
0
 @Override
 protected void onDestroy() {
   if (tts != null) {
     tts.stop();
     tts.shutdown();
   }
   unregisterReceiver(mReceiver);
   super.onDestroy();
 }
示例#19
0
  private void displayAlert(String displayMessage) {
    alertMessage.setMessage(displayMessage);
    if (TTS == 1) {

      talker.setLanguage(Locale.US);
      talker.speak(displayMessage, TextToSpeech.QUEUE_ADD, null);
    }
    alertMessage.show();
  }
  @Override
  public void onDestroy() {
    // Don't forget to shutdown!
    if (mTts != null) {
      mTts.stop();
      mTts.shutdown();
    }

    super.onDestroy();
  }
示例#21
0
 public void onInit(final int status) {
   if (status == TextToSpeech.SUCCESS) {
     final int result = mTts.setLanguage(Locale.US);
     mTts.setSpeechRate(0.9F);
     mTts.setPitch(0.9F);
     if (result != TextToSpeech.LANG_MISSING_DATA && result != TextToSpeech.LANG_NOT_SUPPORTED) {
       mTts.speak(spokenText, TextToSpeech.QUEUE_FLUSH, null);
     }
   }
 }
示例#22
0
  @Override
  public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
      Log.d("flow", "success");

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textToSpeech.speak(voiceResponse, TextToSpeech.QUEUE_FLUSH, null, null);
      } else {
        textToSpeech.speak(voiceResponse, TextToSpeech.QUEUE_ADD, null);
      }
    }
  }
示例#23
0
  /**
   * Plays an earcon given its id.
   *
   * @param earconId The id of the earcon to be played.
   */
  private void playEarcon(int earconId) {
    String earconName = mEarconNames.get(earconId);
    if (earconName == null) {
      // we do not know the sound id, hence we need to load the sound
      int resourceId = sSoundsResourceIds.get(earconId);
      earconName = "[" + earconId + "]";
      mTts.addEarcon(earconName, getPackageName(), resourceId);
      mEarconNames.put(earconId, earconName);
    }

    mTts.playEarcon(earconName, QUEUING_MODE_INTERRUPT, null);
  }
示例#24
0
  // 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();
  }
示例#25
0
 @Override // Fragment
 public void onPause() {
   boolean orientationChanged = isOrientationChanged();
   super.onPause();
   if (!orientationChanged && this.textToSpeech != null) {
     textToSpeech.stop();
     textToSpeech.shutdown();
     textToSpeech = null;
     if (BuildConfig.DEBUG)
       Log.d(engSpaActivity.getTag(), "EngSpaFragment.onPause(); textToSpeech closed");
   }
 }
示例#26
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);
  }
示例#27
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());
  }
示例#28
0
        @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);
        }
示例#29
0
 public void onDestroy() {
   super.onDestroy();
   All_In_One.ServiceState(false);
   mShakeDetector.setOnShakeListener(
       new OnShakeListener() {
         @Override
         public void onShake(int count) {
           // Disable
         }
       });
   if (mTts != null) {
     mTts.stop();
     mTts.shutdown();
   }
 }
  @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();
    }
  }