Search in sources :

Example 46 with TextToSpeech

use of android.speech.tts.TextToSpeech in project android_packages_apps_Settings by omnirom.

the class TextToSpeechViewModel method getTtsAndWhetherNew.

/*
     * An accessor method to get the TTS object. Returns a pair of the TTS object and a boolean
     * indicating whether the TTS object was newly created or not.
     */
protected Pair<TextToSpeech, Boolean> getTtsAndWhetherNew(TextToSpeech.OnInitListener listener) {
    boolean ttsCreated = false;
    if (mTts == null) {
        mTts = new TextToSpeech(this.mApplication, listener);
        ttsCreated = true;
    }
    return Pair.create(mTts, ttsCreated);
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech)

Example 47 with TextToSpeech

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

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 48 with TextToSpeech

use of android.speech.tts.TextToSpeech in project XobotOS by xamarin.

the class WebView method addAccessibilityApisToJavaScript.

/**
     * Adds accessibility APIs to JavaScript.
     *
     * Note: This method is responsible to performing the necessary
     *       check if the accessibility APIs should be exposed.
     */
private void addAccessibilityApisToJavaScript() {
    if (AccessibilityManager.getInstance(mContext).isEnabled() && getSettings().getJavaScriptEnabled()) {
        // exposing the TTS for now ...
        mTextToSpeech = new TextToSpeech(getContext(), null);
        addJavascriptInterface(mTextToSpeech, ALIAS_ACCESSIBILITY_JS_INTERFACE);
    }
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech)

Example 49 with TextToSpeech

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

the class TextToSpeechTests method blockingInitAndVerify.

private void blockingInitAndVerify(final String engine, int errorCode) throws InterruptedException {
    TextToSpeech.OnInitListener listener = LittleMock.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 50 with TextToSpeech

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

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)

Aggregations

TextToSpeech (android.speech.tts.TextToSpeech)103 Test (org.junit.Test)34 Locale (java.util.Locale)18 TtsEngines (android.speech.tts.TtsEngines)15 ActivityNotFoundException (android.content.ActivityNotFoundException)12 Intent (android.content.Intent)12 ContentResolver (android.content.ContentResolver)10 MissingResourceException (java.util.MissingResourceException)10 IntentFilter (android.content.IntentFilter)8 TextView (android.widget.TextView)7 Config (org.robolectric.annotation.Config)7 BluetoothAdapter (android.bluetooth.BluetoothAdapter)6 Handler (android.os.Handler)6 UtteranceProgressListener (android.speech.tts.UtteranceProgressListener)6 ArrayAdapter (android.widget.ArrayAdapter)6 Context (android.content.Context)5 HashMap (java.util.HashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Bundle (android.os.Bundle)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3