List of usage examples for android.speech.tts TextToSpeech SUCCESS
int SUCCESS
To view the source code for android.speech.tts TextToSpeech SUCCESS.
Click Source Link
From source file:com.perchtech.humraz.blind.libraryact.java
/** * Initializes the UI and creates the detector pipeline. *//*from www . j a va 2 s. co m*/ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); mContext = getApplicationContext(); setContentView(R.layout.ocr_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); // Set good defaults for capturing text. boolean autoFocus = true; boolean useFlash = false; // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show(); // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { Log.d("OnInitListener", "Text to speech engine started successfully."); tts.setLanguage(Locale.US); } else { Log.d("OnInitListener", "Error starting the text to speech engine."); } } }; tts = new TextToSpeech(this.getApplicationContext(), listener); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { speakOut("library mode"); } }, 500); }
From source file:com.bellman.bible.service.device.speak.TextToSpeechController.java
@Override public void onInit(int status) { Log.d(TAG, "Tts initialised"); boolean isOk = false; // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. if (mTts != null && status == TextToSpeech.SUCCESS) { Log.d(TAG, "Tts initialisation succeeded"); boolean localeOK = false; Locale locale = null;//from w w w . j a v a 2 s.com for (int i = 0; i < localePreferenceList.size() && !localeOK; i++) { locale = localePreferenceList.get(i); Log.d(TAG, "Checking for locale:" + locale); int result = mTts.setLanguage(locale); localeOK = ((result != TextToSpeech.LANG_MISSING_DATA) && (result != TextToSpeech.LANG_NOT_SUPPORTED)); if (localeOK) { Log.d(TAG, "Successful locale:" + locale); currentLocale = locale; } } if (!localeOK) { Log.e(TAG, "TTS missing or not supported"); // Language data is missing or the language is not supported. ttsLanguageSupport.addUnsupportedLocale(locale); showError(R.string.tts_lang_not_available, new Exception("Tts missing or not supported")); } else { // The TTS engine has been successfully initialized. ttsLanguageSupport.addSupportedLocale(locale); int ok = mTts.setOnUtteranceCompletedListener(this); if (ok == TextToSpeech.ERROR) { Log.e(TAG, "Error registering onUtteranceCompletedListener"); } else { // everything seems to have succeeded if we get here isOk = true; // say the text startSpeaking(); // add event listener to stop on call stopIfPhoneCall(); } } } else { Log.d(TAG, "Tts initialisation failed"); // Initialization failed. showError(R.string.error_occurred, new Exception("Tts Initialisation failed")); } if (!isOk) { shutdown(); } }
From source file:com.app.azza.ocr.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *///from w ww. j av a 2s .c om @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocr_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); // Set good defaults for capturing text. boolean autoFocus = true; boolean useFlash = false; // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show(); // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { Log.d("OnInitListener", "Text to speech engine started successfully."); tts.setLanguage(Locale.US); } else { Log.d("OnInitListener", "Error starting the text to speech engine."); } } }; tts = new TextToSpeech(this.getApplicationContext(), listener); }
From source file:com.microsoft.AzureIntelligentServicesExample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this._logText = (EditText) findViewById(R.id.editText1); this._startButton = (Button) findViewById(R.id.button1); tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override// w w w . j a v a2 s . c o m public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.US); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "This Language is not supported"); Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); } } else { Log.e("TTS", "Initilization Failed!"); } } }); ImageView sendBtn = (ImageView) findViewById(R.id.sendBtn); final EditText message = (EditText) findViewById(R.id.message); sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { _logText.append("ME : " + message.getText().toString() + "\n"); speakOut(message.getText().toString()); message.setText(""); } }); if (getString(R.string.primaryKey).startsWith("Please")) { new AlertDialog.Builder(this).setTitle(getString(R.string.add_subscription_key_tip_title)) .setMessage(getString(R.string.add_subscription_key_tip)).setCancelable(false).show(); } // setup the buttons final MainActivity This = this; this._startButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { This.StartButton_Click(arg0); } }); }
From source file:com.example.sherrychuang.splitsmart.Activity.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *///w ww .ja va2s. c om @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocr_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); itemInputs = new ArrayList<>(); e = (Event) getIntent().getSerializableExtra("event"); itemInputsTest = new ArrayList<>(); String s = "Apple"; List<Tag> tmp = new ArrayList<Tag>(); itemInputsTest.add(new ItemInput(false, s, "", tmp)); // Set good defaults for capturing text. itemInputsTest.get(0).setPrice("2"); ItemAr = new String[itemInputs.size()]; PriceAr = new String[itemInputs.size()]; for (int j = 0; j < itemInputs.size(); j++) { ItemAr[j] = itemInputs.get(j).getItemName(); PriceAr[j] = itemInputs.get(j).getPrice(); } boolean autoFocus = true; boolean useFlash = false; // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); // TODO: Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { Log.d("TTS", "Text to speech engine started successfully."); tts.setLanguage(Locale.US); } else { Log.d("TTS", "Error starting the text to speech engine."); } } }; tts = new TextToSpeech(this.getApplicationContext(), listener); //button for saving item and price Button btn = (Button) findViewById(R.id.done); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Log.d("OcrCaptureActivity", "done"); Intent myIntent = new Intent(OcrCaptureActivity.this, BillPage.class); myIntent.putExtra("Event", e); myIntent.putExtra("ItemInput", ItemAr); myIntent.putExtra("PriceInput", PriceAr); onPause(); OcrCaptureActivity.this.startActivity(myIntent); /*if(itemInputs!=null) { Intent myIntent = new Intent(view.getContext(), BillContentPage.class); myIntent.putExtra("ItemInput", itemInputsTest); OcrCaptureActivity.this.startActivity(myIntent); }*/ } }); }
From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java
public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { int result = mTts.setLanguage(Locale.US); // Try this someday for some interesting results. // int result mTts.setLanguage(Locale.FRANCE); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e(TAG, "Language is not available."); } else {/*from w w w .j a v a 2s . co m*/ this.twitter = G.checkTwitterCreds(); if (twitter == null) { startActivityForResult(new Intent(this, TwitterLoginActivity.class), G.REQCODE_TWITTER_LOGIN); } else { speakTwit(); } } } else { Log.e(TAG, "TTS init error: " + status); } }
From source file:com.xengar.android.englishverbs.ui.DetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_details); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* w w w . j av a2s. c om*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); Bundle bundle = getIntent().getExtras(); demo = bundle.getBoolean(DEMO_MODE, false); verbID = bundle.getLong(VERB_ID, -1); String title = bundle.getString(VERB_NAME); getSupportActionBar().setTitle(title); // Invalidate the options menu, so the "Edit" menu option can be hidden. invalidateOptionsMenu(); //Text infinitive = (TextView) findViewById(R.id.infinitive); simplePast = (TextView) findViewById(R.id.simple_past); pastParticiple = (TextView) findViewById(R.id.past_participle); pInfinitive = (TextView) findViewById(R.id.phonetic_infinitive); pSimplePast = (TextView) findViewById(R.id.phonetic_simple_past); pPastParticiple = (TextView) findViewById(R.id.phonetic_past_participle); definition = (TextView) findViewById(R.id.definition); translation = (TextView) findViewById(R.id.translation); sample1 = (TextView) findViewById(R.id.sample1); sample2 = (TextView) findViewById(R.id.sample2); sample3 = (TextView) findViewById(R.id.sample3); // define click listeners LinearLayout header = (LinearLayout) findViewById(R.id.play_infinitive); header.setOnClickListener(this); header = (LinearLayout) findViewById(R.id.play_simple_past); header.setOnClickListener(this); header = (LinearLayout) findViewById(R.id.play_past_participle); header.setOnClickListener(this); // initialize Speaker tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.US); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { if (LOG) { Log.e("TTS", "This Language is not supported"); } } } else { if (LOG) { Log.e("TTS", "Initilization Failed!"); } } } }); // Initialize a loader to read the verb data from the database and display it getLoaderManager().initLoader(EXISTING_VERB_LOADER, null, this); showFavoriteButtons(); // Obtain the FirebaseAnalytics instance. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); ActivityUtils.firebaseAnalyticsLogEventSelectContent(mFirebaseAnalytics, PAGE_VERB_DETAILS, PAGE_VERB_DETAILS, TYPE_PAGE); // create AdMob banner listener = new LogAdListener(mFirebaseAnalytics, DETAILS_ACTIVITY); mAdView = ActivityUtils.createAdMobBanner(this, listener); if (demo) { defineDemoMode(); } }
From source file:com.nbplus.vbroadlistener.BaseActivity.java
@Override public void onInit(int status) { Log.d(TAG, "> TTS onInit()"); LauncherSettings.getInstance(this).setIsCheckedTTSEngine(true); if (status != TextToSpeech.SUCCESS) { Log.e(TAG, String.format("TextToSpeechManager.onInit(%d) fail!", status)); Log.d(TAG, " ??.... ? ??..."); if (mcheckText2SpeechLister != null) { mcheckText2SpeechLister.onCheckResult(null); mText2Speech.shutdown();/* w ww .j a v a2s . com*/ mText2Speech = null; } showText2SpeechAlertDialog(); } else { int result = mText2Speech.setLanguage(Locale.KOREA); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e(TAG, String.format("TextToSpeech.setLanguage(%s) fail!", Locale.KOREA.getDisplayName())); Log.d(TAG, " ??.... ? ??..."); if (mcheckText2SpeechLister != null) { mcheckText2SpeechLister.onCheckResult(null); mText2Speech.shutdown(); mText2Speech = null; } showText2SpeechAlertDialog(); } else { if (mcheckText2SpeechLister != null) { mcheckText2SpeechLister.onCheckResult(mText2Speech); } else { if (mcheckText2SpeechLister != null) { mcheckText2SpeechLister.onCheckResult(null); mText2Speech.shutdown(); mText2Speech = null; } } } } }
From source file:org.thecongers.mcluster.MainActivity.java
public void onInit(int initStatus) { if (initStatus == TextToSpeech.SUCCESS) { if (text2speech.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE) text2speech.setLanguage(Locale.US); } else if (initStatus == TextToSpeech.ERROR) { Log.d(TAG, "Text to Speech startup failed..."); }//from w w w . ja va2s . c o m }
From source file:com.surveyorexpert.TalkToMe.java
@Override public void onInit(int status) { if (status == TextToSpeech.SUCCESS) { speak.setEnabled(true);/*from www . j a va 2s . co m*/ } else { //failed to init finish(); } }