@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();
  }
Beispiel #2
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);
     }
   }
 }
  /**
   * 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);
  }
  public void textToSpeechTeller(String spokenText) {
    textToSpeech = new TextToSpeech(context, this);
    textToSpeech.setLanguage(Locale.US);
    textToSpeech.setPitch((float) 2);

    if (spokenText.toLowerCase().contains("how ")
        || spokenText.toLowerCase().contains(" how ")
        || spokenText.toLowerCase().equals("how")
        || spokenText.toLowerCase().equals("how's")) {
      voiceResponse = howResponses[random.nextInt((howResponses.length))];
    } else if (spokenText.toLowerCase().contains("who ")
        || spokenText.toLowerCase().contains(" who ")
        || spokenText.toLowerCase().equals("who")
        || spokenText.toLowerCase().equals("who's")) {
      voiceResponse = whoResponses[random.nextInt((whoResponses.length))];
    } else if (spokenText.toLowerCase().contains("when ")
        || spokenText.toLowerCase().contains(" when ")
        || spokenText.toLowerCase().equals("when")) {
      voiceResponse = whenResponses[random.nextInt((whenResponses.length))];
    } else if (spokenText.toLowerCase().contains("what ")
        || spokenText.toLowerCase().contains(" what ")
        || spokenText.toLowerCase().equals("what")
        || spokenText.toLowerCase().equals("what's")) {
      voiceResponse = whatResponses[random.nextInt((whatResponses.length))];
    } else if (spokenText.toLowerCase().contains("where ")
        || spokenText.toLowerCase().contains(" where ")
        || spokenText.toLowerCase().equals("where")
        || spokenText.toLowerCase().equals("where's")) {
      voiceResponse = whereResponses[random.nextInt((whereResponses.length))];
    } else if (spokenText.toLowerCase().equals("am")
        || spokenText.toLowerCase().equals("will")
        || spokenText.toLowerCase().contains("am ")
        || spokenText.toLowerCase().contains("will ")
        || spokenText.toLowerCase().contains(" am ")
        || spokenText.toLowerCase().contains(" will ")) {
      voiceResponse = amAndWillResponses[random.nextInt((amAndWillResponses.length))];
    } else voiceResponse = "Ask me a real question";
  }
 private void speakOut(String text) {
   tts.setPitch(1.3f);
   tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
 }
        @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;
          }
        }