List of usage examples for android.speech.tts TextToSpeech QUEUE_FLUSH
int QUEUE_FLUSH
To view the source code for android.speech.tts TextToSpeech QUEUE_FLUSH.
Click Source Link
From source file:com.example.michel.facetrack.FaceTrackerActivity.java
/** * Initializes the UI and initiates the creation of a face detector. */// www .j a va 2 s . c om @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay); // 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(); } else { requestCameraPermission(); } mTTS = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status != TextToSpeech.ERROR) { mTTS.setLanguage(Locale.CANADA); // mTTS.setOnUtteranceCompletedListener(new TextToSpeech.OnUtteranceCompletedListener() { // @Override // public void onUtteranceCompleted(String utteranceId) { // startSpeechToText(); // } // }); String toSpeak = "Blind spot opened. What do you want?"; mTTS.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null); waitStartSTT(8000); } } }); /*mPreview.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCameraSource.takePicture(new CameraSource.ShutterCallback() { @Override public void onShutter() { } }, new CameraSource.PictureCallback() { @Override public void onPictureTaken(byte[] bytes) { String file_timestamp = Long.toString(System.currentTimeMillis()); Log.e("File: ", Environment.getExternalStorageDirectory() + "/" + file_timestamp + ".jpg"); final File file = new File(Environment.getExternalStorageDirectory() + "/" + file_timestamp + ".jpg"); try { save(bytes, file); String toSpeak = "Image saved"; mTTS.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null); Toast.makeText(FaceTrackerActivity.this, "Saved to " + Environment.getExternalStorageDirectory() + "/" + file_timestamp + ".jpg", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } } private void save(byte[] bytes, final File file) throws IOException { OutputStream output = null; try { output = new FileOutputStream(file); output.write(bytes); } finally { if (null != output) { output.close(); } } Float happiness = sendPhotoToAzure(file); // Sending a blob (photo) to the Azure Storage String photo_url = "https://blindspot.blob.core.windows.net/image/" + file.getName(); Log.e("Photo_url : ", photo_url); // Float happiness = getHappiness(photo_url); // Call the Microsoft's Emotion API using the photo url Log.e("Happiness: ", Float.toString(happiness)); } }); } });*/ lastFaceTime = System.currentTimeMillis(); }
From source file:it.iziozi.iziozi.gui.IOBoardActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_board); this.mDecorView = getWindow().getDecorView(); this.mActiveConfig = IOConfiguration.getSavedConfiguration(); if (this.mActiveConfig == null) { this.mActiveConfig = new IOConfiguration(); showHintAlert();/*from w w w . ja v a2 s .co m*/ } else { lockUI(); } mActualLevel = mActiveConfig.getLevel(); mFrameLayout = (FrameLayout) findViewById(R.id.mainLayoutTableContainer); FragmentManager fm = getSupportFragmentManager(); fm.beginTransaction().add(mFrameLayout.getId(), IOPaginatedBoardFragment.newInstance(mActualLevel)) .commit(); setupNavButtons(); /* * Neurosky Mindwave support * */ btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter != null) { tgDevice = new TGDevice(btAdapter, handler); } this.tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int i) { if (tts.isLanguageAvailable(Locale.getDefault()) >= 0) tts.setLanguage(Locale.getDefault()); else tts.setLanguage(Locale.ENGLISH); tts.speak(getResources().getString(R.string.tts_ready), TextToSpeech.QUEUE_FLUSH, null); mCanSpeak = true; } }); this.mDecorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { // Note that system bars will only be "visible" if none of the // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set. if (visibility == View.VISIBLE && IOBoardActivity.this.mUnlockAlert == null) { // TODO: The system bars are visible. if (mUILocked && !IOGlobalConfiguration.isEditing && canGoImmersive()) showUnlockAlert(); } else { // TODO: The system bars are NOT visible. } } }); }
From source file:me.hammarstrom.imagerecognition.activities.MainActivity.java
/** * Helper method to show / hide progress bar * * @param show if progress should be shown or not *///from ww w .j a va 2 s . com private void showLoading(final boolean show) { ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mLoadingLayout, "alpha", show ? 0f : 1f, show ? 1f : 0f); alphaAnimator.setDuration(200); alphaAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (!show) { mLoadingLayout.setVisibility(View.GONE); } } @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); if (show) { mLoadingLayout.setAlpha(0f); mLoadingLayout.setVisibility(View.VISIBLE); mTts.speak(getString(R.string.tts_processing_image), TextToSpeech.QUEUE_FLUSH, null); } } }); alphaAnimator.start(); }
From source file:com.eng.arab.translator.androidtranslator.ShowDetailsMonth.java
private void speakWords(String speech) { //speak straight away myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null); }
From source file:com.surveyorexpert.TalkToMe.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SPEECH_REQUEST_CODE) { if (resultCode == RESULT_OK) { ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (matches.size() == 0) { tts.speak("Heard nothing", TextToSpeech.QUEUE_FLUSH, null); } else { String mostLikelyThingHeard = matches.get(0); String magicWord = this.getResources().getString(R.string.magicword); if (mostLikelyThingHeard.equals(magicWord)) { tts.speak("You said the magic word!", TextToSpeech.QUEUE_FLUSH, null); } else { // tts.speak("Recognised " + mostLikelyThingHeard + " Is that OK", TextToSpeech.QUEUE_FLUSH, null); gotMessage = mostLikelyThingHeard; tts.speak(gotMessage + " OK?", TextToSpeech.QUEUE_FLUSH, null); //intent.putExtra("description",mostLikelyThingHeard); }//from w w w .j a v a 2 s . co m } result.setText("heard: " + matches); // Toast.makeText(getBaseContext(),"TalkToMe Done " + gotMessage, Toast.LENGTH_LONG).show(); } else { Log.d(TAG, "result NOT ok"); } } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.example.robert.bluetoothnew.BluetoothChatFragment.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void speakOut(String content) { CharSequence text = content;/* w ww .j a v a 2 s. c o m*/ tts.setPitch(0.5f); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, content); }
From source file:in.codehex.arrow.MainActivity.java
@Override public void onLocationChanged(Location loc) { lat = loc.getLatitude();/*from www . j a v a2s . c om*/ lng = loc.getLongitude(); LatLng latLng = new LatLng(lat, lng); final Location userLocation = new Location("user"); userLocation.setLatitude(lat); userLocation.setLongitude(lng); if (getBatteryLevel() < 20) { textToSpeech.speak("Your battery is at " + (int) getBatteryLevel() + "%", TextToSpeech.QUEUE_FLUSH, null, null); } else if (!directionItemList.isEmpty() && !isDestinationAvailable) { for (int i = 0; i < directionItemList.size(); i++) { String polyline = directionItemList.get(i).getPolyline(); final List<LatLng> decodedPath = PolyUtil.decode(polyline); if (PolyUtil.isLocationOnPath(latLng, decodedPath, true, 40)) { wayPoint = i; double endLat = directionItemList.get(i).getEndLat(); double endLng = directionItemList.get(i).getEndLng(); Location endLocation = new Location("end"); endLocation.setLatitude(endLat); endLocation.setLongitude(endLng); float distance = userLocation.distanceTo(endLocation); if (distance <= 20 && (i + 1) == directionItemList.size()) { String data = "You have reached your final destination."; textToSpeech.speak(data, TextToSpeech.QUEUE_FLUSH, null, null); textInstruction.setText(data); updateLocation(); dataPreferences.edit().clear().apply(); directionItemList.clear(); } else if (distance <= 20) { updateLocation(); } else if (!directionItemList.get(i).isPathInstruction()) { String data = directionItemList.get(i).getData(); textToSpeech.speak(data, TextToSpeech.QUEUE_FLUSH, null, null); textInstruction.setText(data); directionItemList.get(i).setPathInstruction(true); } else textToSpeech.speak("Walk straight for the distance of " + (int) distance + " meters.", TextToSpeech.QUEUE_FLUSH, null, null); } else { new Runnable() { @Override public void run() { List<Float> list = new ArrayList<>(); for (int j = 0; j < decodedPath.size(); j++) { Location endLocation = new Location("end"); endLocation.setLatitude(decodedPath.get(j).latitude); endLocation.setLongitude(decodedPath.get(j).longitude); list.add(userLocation.distanceTo(endLocation)); } if (!list.isEmpty()) { Collections.sort(list); textToSpeech.speak( "You are " + (int) list.get(0).floatValue() + " meters away from the correct path.", TextToSpeech.QUEUE_FLUSH, null, null); } } }.run(); } } } }
From source file:onion.chat.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); db = Database.getInstance(this); tor = Tor.getInstance(this); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*ww w.j a va2 s .c om*/ t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if (status != TextToSpeech.ERROR) { t1.setLanguage(Locale.US); } } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final Dialog[] d = new Dialog[1]; View v = getLayoutInflater().inflate(R.layout.dialog_connect, null); ((TextView) v.findViewById(R.id.id)).setText(Tor.getInstance(MainActivity.this).getID()); v.findViewById(R.id.qr_show).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); showQR(); } }); v.findViewById(R.id.qr_scan).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); scanQR(); } }); v.findViewById(R.id.enter_id).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); addContact(); } }); v.findViewById(R.id.share_id).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d[0].cancel(); inviteFriend(); } }); d[0] = new AlertDialog.Builder(MainActivity.this) //.setTitle(R.string.add_contact) .setView(v).show(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); startService(new Intent(this, HostService.class)); findViewById(R.id.myname).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { changeName(); } }); findViewById(R.id.myaddress).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showQR(); } }); contactPage = getLayoutInflater().inflate(R.layout.page_contacts, null); requestPage = getLayoutInflater().inflate(R.layout.page_requests, null); contactRecycler = (RecyclerView) contactPage.findViewById(R.id.contactRecycler); requestRecycler = (RecyclerView) requestPage.findViewById(R.id.requestRecycler); contactEmpty = contactPage.findViewById(R.id.contactEmpty); requestEmpty = requestPage.findViewById(R.id.requestEmpty); contactRecycler.setLayoutManager(new LinearLayoutManager(this)); contactRecycler.setAdapter(new RecyclerView.Adapter<ContactViewHolder>() { @Override public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final ContactViewHolder viewHolder = new ContactViewHolder( getLayoutInflater().inflate(R.layout.item_contact, parent, false)); viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String toSpeak = viewHolder.name.getText().toString(); Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show(); t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null); startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("chat:" + viewHolder.address.getText()), getApplicationContext(), ChatActivity.class)); } }); viewHolder.itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { contactLongPress(viewHolder.address.getText().toString(), viewHolder.name.getText().toString()); return true; } }); return viewHolder; } @Override public void onBindViewHolder(ContactViewHolder holder, int position) { contactCursor.moveToPosition(position); holder.address.setText(contactCursor.getString(0)); String name = contactCursor.getString(1); if (name == null || name.equals("")) name = "Anonymous"; holder.name.setText(name); long n = contactCursor.getLong(2); if (n > 0) { holder.badge.setVisibility(View.VISIBLE); holder.count.setText("" + n); } else { holder.badge.setVisibility(View.GONE); } } @Override public int getItemCount() { return contactCursor != null ? contactCursor.getCount() : 0; } }); requestRecycler.setLayoutManager(new LinearLayoutManager(this)); requestRecycler.setAdapter(new RecyclerView.Adapter<ContactViewHolder>() { @Override public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final ContactViewHolder viewHolder = new ContactViewHolder( getLayoutInflater().inflate(R.layout.item_contact_request, parent, false)); viewHolder.accept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String addr = viewHolder.address.getText().toString(); db.acceptContact(addr); Client.getInstance(getApplicationContext()).startAskForNewMessages(addr); updateContactList(); } }); viewHolder.decline.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String address = viewHolder.address.getText().toString(); final String name = viewHolder.name.getText().toString(); db.removeContact(address); updateContactList(); Snackbar.make(findViewById(R.id.drawer_layout), R.string.contact_request_declined, Snackbar.LENGTH_LONG).setAction(R.string.undo, new View.OnClickListener() { @Override public void onClick(View v) { db.addContact(address, false, true, name); updateContactList(); } }).show(); } }); return viewHolder; } @Override public void onBindViewHolder(ContactViewHolder holder, int position) { requestCursor.moveToPosition(position); holder.address.setText(requestCursor.getString(0)); String name = requestCursor.getString(1); if (name == null || name.equals("")) name = "Anonymous"; holder.name.setText(name); } @Override public int getItemCount() { return requestCursor != null ? requestCursor.getCount() : 0; } }); tabLayout = (TabLayout) findViewById(R.id.tabLayout); final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager); viewPager.setAdapter(new PagerAdapter() { @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(final ViewGroup container, int position) { View v = position == 0 ? contactPage : requestPage; container.addView(v); return v; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } }); tabLayout.setupWithViewPager(viewPager); tabLayout.getTabAt(0).setText(R.string.tab_contacts); tabLayout.getTabAt(1).setText(R.string.tab_requests); for (int i = 0; i < 2; i++) { View v = getLayoutInflater().inflate(R.layout.tab_header, null, false); ((TextView) v.findViewById(R.id.text)).setText(tabLayout.getTabAt(i).getText().toString()); ((TextView) v.findViewById(R.id.badge)).setText(""); v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); tabLayout.getTabAt(i).setCustomView(v); } tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { if (tab.getPosition() == 1) { db.clearNewRequests(); } viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); updateContactList(); handleIntent(); // inform(); listen(); }
From source file:com.vyasware.vaani.MainActivity.java
private void performAction(String input) { String[] verbs = { "", "", "", "?", "", "?", "", "", "", "", "", "", "", "", "", "weather", "?", "?", "", "", "?" }; String[] actions = { "call", "call", "call", "call", "msg", "msg", "msg", "msg", "open", "open", "open", "weather", "weather", "weather", "weather", "weather", "greet", "greet", "greet", "greet", "greet" }; String[] sentence = input.split(" "); String action = "", noun = "", result = ""; int verbindex = -1, nounindex = -1; for (String word : sentence) { //out.println(word); for (int i = 0; i < verbs.length; i++) { //System.out.println(verbs[i]); if (word.equalsIgnoreCase(verbs[i])) verbindex = i;/*from ww w.j av a2 s. c o m*/ } if (verbindex >= 0) { // out.println("true"); action = actions[verbindex]; System.out.println(action); break; } } for (int j = 0; j < sentence.length; j++) { if (sentence[j].equalsIgnoreCase("")) { nounindex = j - 1; } } if (nounindex >= 0) noun = sentence[nounindex]; String search = "google!"; if (action.equals("")/*||noun.equals("")*/) { tts.speak(search, TextToSpeech.QUEUE_FLUSH, null); Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, returnedText.getText()); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); } else if (action.equals("call")) doCall(noun); else if (action.equals("msg")) doMsg(noun); else if (action.equals("open")) doOpen(sentence); else if (action.equals("weather")) doWeather(); else if (action.equals("greet")) doGreet(); // tts.speak(result,TextToSpeech.QUEUE_FLUSH, null); }
From source file:com.bdcorps.videonews.MainActivity.java
public void speak(String s) { Log.d("SSS", "to speak: " + s); if (s != null) { HashMap<String, String> myHashAlarm = new HashMap<String, String>(); myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "completed"); AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int amStreamMusicMaxVol = am.getStreamMaxVolume(am.STREAM_SYSTEM); am.setStreamVolume(am.STREAM_SYSTEM, amStreamMusicMaxVol, 0); mTts.speak(s, TextToSpeech.QUEUE_FLUSH, myHashAlarm); } else {/*from w w w. j av a 2s . c o m*/ speakNext(); } }