Search in sources :

Example 11 with TextToSpeech

use of android.speech.tts.TextToSpeech in project android_frameworks_base by AOSPA.

the class ScoAudioTest method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.scoaudiotest);
    mScoStateTxt = (TextView) findViewById(R.id.scoStateTxt);
    mVdStateTxt = (TextView) findViewById(R.id.vdStateTxt);
    IntentFilter intentFilter = new IntentFilter(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
    intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
    intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
    registerReceiver(mReceiver, intentFilter);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioManager2 = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    mHandler = new Handler();
    mMediaControllers[0] = new SimplePlayerController(this, R.id.playPause1, R.id.stop1, R.raw.sine440_mo_16b_16k, AudioManager.STREAM_BLUETOOTH_SCO);
    TextView name = (TextView) findViewById(R.id.playPause1Text);
    name.setText("VOICE_CALL stream");
    mScoButton = (ToggleButton) findViewById(R.id.ForceScoButton);
    mScoButton.setOnCheckedChangeListener(mForceScoChanged);
    mForceScoOn = false;
    mScoButton.setChecked(mForceScoOn);
    mVoiceDialerButton = (ToggleButton) findViewById(R.id.VoiceDialerButton);
    mVoiceDialerButton.setOnCheckedChangeListener(mVoiceDialerChanged);
    mVoiceDialerOn = false;
    mVoiceDialerButton.setChecked(mVoiceDialerOn);
    mMediaControllers[1] = new SimpleRecordController(this, R.id.recStop1, 0, "Sco_record_");
    mTtsInited = false;
    mTts = new TextToSpeech(this, new TtsInitListener());
    mTtsParams = new HashMap<String, String>();
    mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_BLUETOOTH_SCO));
    mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UTTERANCE);
    mSpeakText = (EditText) findViewById(R.id.speakTextEdit);
    mSpeakText.setOnKeyListener(mSpeakKeyListener);
    mSpeakText.setText("sco audio test sentence");
    mTtsToFileButton = (ToggleButton) findViewById(R.id.TtsToFileButton);
    mTtsToFileButton.setOnCheckedChangeListener(mTtsToFileChanged);
    mTtsToFile = true;
    mTtsToFileButton.setChecked(mTtsToFile);
    mModeSpinner = (Spinner) findViewById(R.id.modeSpinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mModeStrings);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mModeSpinner.setAdapter(adapter);
    mModeSpinner.setOnItemSelectedListener(mModeChanged);
    mCurrentMode = mAudioManager.getMode();
    mModeSpinner.setSelection(mCurrentMode);
    mBluetoothHeadsetDevice = null;
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter != null) {
        btAdapter.getProfileProxy(this, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
    }
    sVoiceCommandIntent = new Intent(Intent.ACTION_VOICE_COMMAND);
    sVoiceCommandIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
Also used : IntentFilter(android.content.IntentFilter) Handler(android.os.Handler) Intent(android.content.Intent) TextToSpeech(android.speech.tts.TextToSpeech) TextView(android.widget.TextView) BluetoothAdapter(android.bluetooth.BluetoothAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 12 with TextToSpeech

use of android.speech.tts.TextToSpeech in project platform_frameworks_base by android.

the class TextToSpeechTests method blockingInitAndVerify.

private void blockingInitAndVerify(final String engine, int errorCode) throws InterruptedException {
    TextToSpeech.OnInitListener listener = Mockito.mock(TextToSpeech.OnInitListener.class);
    final CountDownLatch latch = new CountDownLatch(1);
    doCountDown(latch).when(listener).onInit(errorCode);
    mTts = new TextToSpeech(getInstrumentation().getTargetContext(), listener, engine, MOCK_PACKAGE, false);
    awaitCountDown(latch, 5, TimeUnit.SECONDS);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with TextToSpeech

use of android.speech.tts.TextToSpeech in project LEGO-MINDSTORMS-MINDdroid by NXT.

the class MINDdroid method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(requestCode) {
        case REQUEST_CONNECT_DEVICE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                // Get the device MAC address and start a new bt communicator thread
                String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
                pairing = data.getExtras().getBoolean(DeviceListActivity.PAIRING);
                startBTCommunicator(address);
            }
            break;
        case REQUEST_ENABLE_BT:
            // When the request to enable Bluetooth returns
            switch(resultCode) {
                case Activity.RESULT_OK:
                    btOnByUs = true;
                    selectNXT();
                    break;
                case Activity.RESULT_CANCELED:
                    showToast(R.string.bt_needs_to_be_enabled, Toast.LENGTH_SHORT);
                    finish();
                    break;
                default:
                    showToast(R.string.problem_at_connecting, Toast.LENGTH_SHORT);
                    finish();
                    break;
            }
            break;
        // will not be called now, since the check intent is not generated                
        case TTS_CHECK_CODE:
            if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                // success, create the TTS instance
                mTts = new TextToSpeech(this, this);
            } else {
                // missing data, install it
                Intent installIntent = new Intent();
                installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installIntent);
            }
            break;
    }
}
Also used : Intent(android.content.Intent) TextToSpeech(android.speech.tts.TextToSpeech)

Example 14 with TextToSpeech

use of android.speech.tts.TextToSpeech in project LEGO-MINDSTORMS-MINDdroid by NXT.

the class MINDdroid method onCreate.

/**
     * Called when the activity is first created. Inititializes all the
     * graphical views.
     */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    thisActivity = this;
    mRobotType = this.getIntent().getIntExtra(SplashMenu.MINDDROID_ROBOT_TYPE, R.id.robot_type_shooterbot);
    setUpByType();
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    StartSound mySound = new StartSound(this);
    mySound.start();
    // setup our view, give it focus and display.
    mView = new GameView(getApplicationContext(), this);
    mView.setFocusable(true);
    setContentView(mView);
    reusableToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
    // experimental TTS support for the lejosMINDdroid project
    mTts = new TextToSpeech(this, // TextToSpeech.OnInitListener
    this);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech)

Example 15 with TextToSpeech

use of android.speech.tts.TextToSpeech in project chefly_android by chef-ly.

the class GetCookingActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_get_cooking);
    speechListener = new ttsUtteranceListener();
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    width = metrics.widthPixels;
    height = metrics.heightPixels;
    //View Pager
    pager = (ViewPager) findViewById(R.id.viewpager);
    // Gesture Detector to repeat the current step when it detects a single tap on the screen
    final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (hasDirections) {
                if (step < directions.size()) {
                    read(directions.get(step));
                } else {
                    read(getResources().getString(R.string.bonAppetit));
                }
            }
            return super.onSingleTapConfirmed(e);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            return super.onDoubleTap(e);
        }
    });
    // set on touch listener to ViewPager
    pager.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }
    });
    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            step = position;
            updateStepText();
            read(directions.get(position));
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    // Text view to display the current step number
    stepText = (TextView) findViewById(R.id.step);
    //Exit Button
    Button exit;
    exit = (Button) findViewById(R.id.exit);
    exit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setResult(RESULT_OK);
            finish();
        }
    });
    ImageButton btnSpeak;
    btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
    btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                textToSpeech.setLanguage(Locale.US);
                // Log.d(TAG, "Quality -> " + textToSpeech.getVoice().getQuality());
                if (directions.size() > 0) {
                    read(directions.get(0));
                }
            }
        }
    });
    // TODO replace with speech recognizer
    Button ingredBtn = (Button) findViewById(R.id.ingredientsBtn);
    ingredBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            ingredientsPopup.show(fm, "Ingredients");
            getSupportFragmentManager().executePendingTransactions();
            if (ingredientsPopup.getDialog().getWindow() != null)
                ingredientsPopup.getDialog().getWindow().setLayout((6 * width) / 7, (4 * height) / 5);
        }
    });
    // TODO replace with speech recognizer
    Button direcBtn = (Button) findViewById(R.id.directionsBtn);
    direcBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            if (directionsPopup != null) {
                directionsPopup.show(fm, "Directions");
                getSupportFragmentManager().executePendingTransactions();
                if (directionsPopup.getDialog().getWindow() != null)
                    directionsPopup.getDialog().getWindow().setLayout((6 * width) / 7, (4 * height) / 5);
            } else {
                Log.d(TAG, "Directions pop up is null.  Directions size = " + directions.size());
            }
        }
    });
    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO }, PERMISSIONS_REQUEST_RECORD_AUDIO);
    //return;
    } else {
        voiceRec.runRec();
    }
}
Also used : GestureDetector(android.view.GestureDetector) TextToSpeech(android.speech.tts.TextToSpeech) DisplayMetrics(android.util.DisplayMetrics) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) MotionEvent(android.view.MotionEvent) FragmentManager(android.support.v4.app.FragmentManager) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button)

Aggregations

TextToSpeech (android.speech.tts.TextToSpeech)25 Intent (android.content.Intent)7 IntentFilter (android.content.IntentFilter)7 TextView (android.widget.TextView)7 BluetoothAdapter (android.bluetooth.BluetoothAdapter)6 Handler (android.os.Handler)6 ArrayAdapter (android.widget.ArrayAdapter)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 TtsEngines (android.speech.tts.TtsEngines)2 Activity (android.app.Activity)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 SensorManager (android.hardware.SensorManager)1 LocationManager (android.location.LocationManager)1 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)1 FragmentManager (android.support.v4.app.FragmentManager)1 ViewPager (android.support.v4.view.ViewPager)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 DisplayMetrics (android.util.DisplayMetrics)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1