private void handleClick(int index) {
   String text = ESLPhrases.get(index);
   if (ttsLoaded) {
     tts.setSpeechRate(0.6f);
     tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
   }
 }
  @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();
  }
Example #3
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);
     }
   }
 }
Example #4
0
  // should be constructed in OnCreate
  public TTScontroller(Context appContext, Handler callWhenDone) {
    mCallWhenDone = callWhenDone;
    this.appContect = appContext;

    TextToSpeech.OnInitListener listener =
        new TextToSpeech.OnInitListener() {
          @Override
          public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
              ttobj.setLanguage(Locale.US);
              // ttobj.setPitch(3f);
              // ttobj.setSpeechRate(0.1f);

              ttobj.setOnUtteranceProgressListener(
                  new UtteranceProgressListener() {

                    @Override
                    public void onDone(String utteranceId) {
                      Log.d("TTScontroller", "OnDone called");
                      if (utteranceId.equals(lastMessageQueued.toString())) {
                        Message msg = new Message();
                        msg.arg1 = 1;
                        mCallWhenDone.sendMessage(msg);
                      }
                    }

                    @Override
                    public void onError(String utteranceId) {}

                    @Override
                    public void onStart(String utteranceId) {}
                  });
            }
          }
        };

    if (alwaysUseFlite)
      ttobj = new TextToSpeech(appContext, listener, "edu.cmu.cs.speech.tts.flite");
    else ttobj = new TextToSpeech(appContext, listener);

    // tingyao
    // adjust speaking rate

    am = (AudioManager) appContect.getSystemService(Context.AUDIO_SERVICE);
    amStreamMusicMaxVol = am.getStreamMaxVolume(am.STREAM_MUSIC);
    am.setStreamVolume(am.STREAM_MUSIC, amStreamMusicMaxVol - 2, 0);
    ttobj.setSpeechRate((float) 0.95);
  }
Example #5
0
  @Override
  public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
      txtS.setLanguage(Locale.US);
      txtS.setSpeechRate(.8f);
      /*
                  if(Build.VERSION.SDK_INT>20){
                      Voice v = new Voice("v1", Locale.US, Voice.QUALITY_VERY_HIGH, Voice.LATENCY_NORMAL, false, false );

                  }
      //            txtS.setVoice()
      //            txtS.setVoice(new Voice(Voice.QUALITY_VERY_HIGH);'

      */
    }
  }
  @Override
  public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {
      ttsLoaded = true;
      tts.setSpeechRate(0.8f);
    }

    int temp = tts.setLanguage(Locale.US);
    if (temp == TextToSpeech.LANG_MISSING_DATA || temp == TextToSpeech.LANG_NOT_SUPPORTED) {
      Log.e(TAG, "Language is not available.");
      ttsLoaded = false;
    }

    // Initialize view pager
    initializePager();
  }
  /** Called when TTS is ready. */
  protected void onTtsReady() {
    Locale locale = Locale.getDefault();
    int languageAvailability = tts.isLanguageAvailable(locale);
    if (languageAvailability == TextToSpeech.LANG_MISSING_DATA
        || languageAvailability == TextToSpeech.LANG_NOT_SUPPORTED) {
      Log.w(TAG, "Default locale not available, use English.");
      locale = Locale.ENGLISH;
      /*
       * TODO: instead of using english, load the language if missing and show a
       * toast if not supported. Not able to change the resource strings to
       * English.
       */
    }
    tts.setLanguage(locale);

    // Slow down the speed just a bit as it is hard to hear when exercising.
    tts.setSpeechRate(TTS_SPEECH_RATE);
  }
  /**
   * Attempt to start speaking an utterance. If it returns true, will call back on start and end.
   *
   * @param utteranceId A unique id for this utterance so that callbacks can be tied to a particular
   *     utterance.
   * @param text The text to speak.
   * @param lang The language code for the text (e.g., "en-US").
   * @param rate The speech rate, in the units expected by Android TextToSpeech.
   * @param pitch The speech pitch, in the units expected by Android TextToSpeech.
   * @param volume The speech volume, in the units expected by Android TextToSpeech.
   * @return true on success.
   */
  @CalledByNative
  private boolean speak(
      int utteranceId, String text, String lang, float rate, float pitch, float volume) {
    assert mInitialized == true;
    if (!lang.equals(mCurrentLanguage)) {
      mTextToSpeech.setLanguage(new Locale(lang));
      mCurrentLanguage = lang;
    }

    mTextToSpeech.setSpeechRate(rate);
    mTextToSpeech.setPitch(pitch);
    HashMap<String, String> params = new HashMap<String, String>();
    if (volume != 1.0) {
      params.put(TextToSpeech.Engine.KEY_PARAM_VOLUME, Double.toString(volume));
    }
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, Integer.toString(utteranceId));
    int result = mTextToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, params);
    return (result == TextToSpeech.SUCCESS);
  }
  @Override
  public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {

      if (tts == null) {
        tts = new TextToSpeech(this, this);
        tts.setSpeechRate(0.8f);
      }
      int result = tts.setLanguage(Locale.ENGLISH);

      if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
        Log.e("TTS", "This Language is not supported");
        Intent installIntent = new Intent();
        installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        startActivity(installIntent);
      }

      speakIt("You are in the impressionist exhibit");
    }
  }
        @Override
        public void handleMessage(Message myMessage) {
          switch (myMessage.getData().getInt("message")) {
            case BTCommunicator.DISPLAY_TOAST:
              showToast(myMessage.getData().getString("toastText"), Toast.LENGTH_SHORT);
              break;
            case BTCommunicator.STATE_CONNECTED:
              connected = true;
              programList = new ArrayList<String>();
              connectingProgressDialog.dismiss();
              updateButtonsAndMenu();
              sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.GET_FIRMWARE_VERSION, 0, 0);
              break;
            case BTCommunicator.MOTOR_STATE:
              if (myBTCommunicator != null) {
                byte[] motorMessage = myBTCommunicator.getReturnMessage();
                int position =
                    byteToInt(motorMessage[21])
                        + (byteToInt(motorMessage[22]) << 8)
                        + (byteToInt(motorMessage[23]) << 16)
                        + (byteToInt(motorMessage[24]) << 24);
                showToast(
                    getResources().getString(R.string.current_position) + position,
                    Toast.LENGTH_SHORT);
              }

              break;

            case BTCommunicator.STATE_CONNECTERROR_PAIRING:
              connectingProgressDialog.dismiss();
              destroyBTCommunicator();
              break;

            case BTCommunicator.STATE_CONNECTERROR:
              connectingProgressDialog.dismiss();
            case BTCommunicator.STATE_RECEIVEERROR:
            case BTCommunicator.STATE_SENDERROR:
              destroyBTCommunicator();
              if (btErrorPending == false) {
                btErrorPending = true;
                // inform the user of the error with an AlertDialog
                AlertDialog.Builder builder = new AlertDialog.Builder(thisActivity);
                builder
                    .setTitle(getResources().getString(R.string.bt_error_dialog_title))
                    .setMessage(getResources().getString(R.string.bt_error_dialog_message))
                    .setCancelable(false)
                    .setPositiveButton(
                        "OK",
                        new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int id) {
                            btErrorPending = false;
                            dialog.cancel();
                            selectNXT();
                          }
                        });
                builder.create().show();
              }

              break;

            case BTCommunicator.FIRMWARE_VERSION:
              if (myBTCommunicator != null) {
                byte[] firmwareMessage = myBTCommunicator.getReturnMessage();
                // check if we know the firmware
                boolean isLejosMindDroid = true;
                for (int pos = 0; pos < 4; pos++) {
                  if (firmwareMessage[pos + 3] != LCPMessage.FIRMWARE_VERSION_LEJOSMINDDROID[pos]) {
                    isLejosMindDroid = false;
                    break;
                  }
                }
                if (isLejosMindDroid) {
                  mRobotType = R.id.robot_type_lejos;
                  setUpByType();
                }
                // afterwards we search for all files on the robot
                sendBTCmessage(BTCommunicator.NO_DELAY, BTCommunicator.FIND_FILES, 0, 0);
              }

              break;

            case BTCommunicator.FIND_FILES:
              if (myBTCommunicator != null) {
                byte[] fileMessage = myBTCommunicator.getReturnMessage();
                String fileName = new String(fileMessage, 4, 20);
                fileName = fileName.replaceAll("\0", "");

                if (mRobotType == R.id.robot_type_lejos
                    || fileName.endsWith(".nxj")
                    || fileName.endsWith(".rxe")) {
                  programList.add(fileName);
                }

                // find next entry with appropriate handle,
                // limit number of programs (in case of error (endless loop))
                if (programList.size() <= MAX_PROGRAMS)
                  sendBTCmessage(
                      BTCommunicator.NO_DELAY,
                      BTCommunicator.FIND_FILES,
                      1,
                      byteToInt(fileMessage[3]));
              }

              break;

            case BTCommunicator.PROGRAM_NAME:
              if (myBTCommunicator != null) {
                byte[] returnMessage = myBTCommunicator.getReturnMessage();
                startRXEprogram(returnMessage[2]);
              }

              break;

            case BTCommunicator.SAY_TEXT:
              if (myBTCommunicator != null) {
                byte[] textMessage = myBTCommunicator.getReturnMessage();
                // evaluate control byte
                byte controlByte = textMessage[2];
                // BIT7: Language
                if ((controlByte & 0x80) == 0x00) mTts.setLanguage(Locale.US);
                else mTts.setLanguage(Locale.getDefault());
                // BIT6: Pitch
                if ((controlByte & 0x40) == 0x00) mTts.setPitch(1.0f);
                else mTts.setPitch(0.75f);
                // BIT0-3: Speech Rate
                switch (controlByte & 0x0f) {
                  case 0x01:
                    mTts.setSpeechRate(1.5f);
                    break;
                  case 0x02:
                    mTts.setSpeechRate(0.75f);
                    break;

                  default:
                    mTts.setSpeechRate(1.0f);
                    break;
                }

                String ttsText = new String(textMessage, 3, 19);
                ttsText = ttsText.replaceAll("\0", "");
                showToast(ttsText, Toast.LENGTH_SHORT);
                mTts.speak(ttsText, TextToSpeech.QUEUE_FLUSH, null);
              }

              break;

            case BTCommunicator.VIBRATE_PHONE:
              if (myBTCommunicator != null) {
                byte[] vibrateMessage = myBTCommunicator.getReturnMessage();
                Vibrator myVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                myVibrator.vibrate(vibrateMessage[2] * 10);
              }

              break;
          }
        }