Search in sources :

Example 1 with TextToSpeech

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

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

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

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

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

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

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

the class TtsEngineSettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.tts_engine_settings);
    mEnginesHelper = new TtsEngines(getActivity());
    final PreferenceScreen root = getPreferenceScreen();
    mLocalePreference = (ListPreference) root.findPreference(KEY_ENGINE_LOCALE);
    mLocalePreference.setOnPreferenceChangeListener(this);
    mEngineSettingsPreference = root.findPreference(KEY_ENGINE_SETTINGS);
    mEngineSettingsPreference.setOnPreferenceClickListener(this);
    mInstallVoicesPreference = root.findPreference(KEY_INSTALL_DATA);
    mInstallVoicesPreference.setOnPreferenceClickListener(this);
    root.setTitle(getEngineLabel());
    root.setKey(getEngineName());
    mEngineSettingsPreference.setTitle(getResources().getString(R.string.tts_engine_settings_title, getEngineLabel()));
    mEngineSettingsIntent = mEnginesHelper.getSettingsIntent(getEngineName());
    if (mEngineSettingsIntent == null) {
        mEngineSettingsPreference.setEnabled(false);
    }
    mInstallVoicesPreference.setEnabled(false);
    if (savedInstanceState == null) {
        mLocalePreference.setEnabled(false);
        mLocalePreference.setEntries(new CharSequence[0]);
        mLocalePreference.setEntryValues(new CharSequence[0]);
    } else {
        // Repopulate mLocalePreference with saved state. Will be updated later with
        // up-to-date values when checkTtsData() calls back with results.
        final CharSequence[] entries = savedInstanceState.getCharSequenceArray(STATE_KEY_LOCALE_ENTRIES);
        final CharSequence[] entryValues = savedInstanceState.getCharSequenceArray(STATE_KEY_LOCALE_ENTRY_VALUES);
        final CharSequence value = savedInstanceState.getCharSequence(STATE_KEY_LOCALE_VALUE);
        mLocalePreference.setEntries(entries);
        mLocalePreference.setEntryValues(entryValues);
        mLocalePreference.setValue(value != null ? value.toString() : null);
        mLocalePreference.setEnabled(entries.length > 0);
    }
    mVoiceDataDetails = getArguments().getParcelable(TtsEnginePreference.FRAGMENT_ARGS_VOICES);
    mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener, getEngineName());
    // Check if data packs changed
    checkTtsData();
    getActivity().registerReceiver(mLanguagesChangedReceiver, new IntentFilter(TextToSpeech.Engine.ACTION_TTS_DATA_INSTALLED));
}
Also used : IntentFilter(android.content.IntentFilter) PreferenceScreen(android.support.v7.preference.PreferenceScreen) TtsEngines(android.speech.tts.TtsEngines) TextToSpeech(android.speech.tts.TextToSpeech)

Example 5 with TextToSpeech

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

the class TextToSpeechSettings method updateDefaultEngine.

private void updateDefaultEngine(String engine) {
    if (DBG)
        Log.d(TAG, "Updating default synth to : " + engine);
    // Disable the "play sample text" preference and the speech
    // rate preference while the engine is being swapped.
    updateWidgetState(false);
    updateEngineStatus(R.string.tts_status_checking);
    // Keep track of the previous engine that was being used. So that
    // we can reuse the previous engine.
    //
    // Note that if TextToSpeech#getCurrentEngine is not null, it means at
    // the very least that we successfully bound to the engine service.
    mPreviousEngine = mTts.getCurrentEngine();
    // Step 1: Shut down the existing TTS engine.
    if (mTts != null) {
        try {
            mTts.shutdown();
            mTts = null;
        } catch (Exception e) {
            Log.e(TAG, "Error shutting down TTS engine" + e);
        }
    }
    // the app binds successfully to the engine.
    if (DBG)
        Log.d(TAG, "Updating engine : Attempting to connect to engine: " + engine);
    mTts = new TextToSpeech(getActivity().getApplicationContext(), mUpdateListener, engine);
    setTtsUtteranceProgressListener();
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) MissingResourceException(java.util.MissingResourceException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

TextToSpeech (android.speech.tts.TextToSpeech)102 Test (org.junit.Test)34 Locale (java.util.Locale)17 TtsEngines (android.speech.tts.TtsEngines)15 Intent (android.content.Intent)12 ActivityNotFoundException (android.content.ActivityNotFoundException)11 ContentResolver (android.content.ContentResolver)9 MissingResourceException (java.util.MissingResourceException)9 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 ArrayAdapter (android.widget.ArrayAdapter)6 UtteranceProgressListener (android.speech.tts.UtteranceProgressListener)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Context (android.content.Context)4 HashMap (java.util.HashMap)4 Bundle (android.os.Bundle)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3