List of usage examples for android.speech RecognizerIntent ACTION_RECOGNIZE_SPEECH
String ACTION_RECOGNIZE_SPEECH
To view the source code for android.speech RecognizerIntent ACTION_RECOGNIZE_SPEECH.
Click Source Link
From source file:lewa.support.v7.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.abc_search_view, this, true); mSearchButton = findViewById(R.id.search_button); mQueryTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mQueryTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSubmitButton = findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = findViewById(R.id.search_voice_btn); mSearchHintIcon = (ImageView) findViewById(R.id.search_mag_icon); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mSubmitButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mQueryTextView.setOnClickListener(mOnClickListener); mQueryTextView.addTextChangedListener(mTextWatcher); mQueryTextView.setOnEditorActionListener(mOnEditorActionListener); mQueryTextView.setOnItemClickListener(mOnItemClickListener); mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener); mQueryTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); }/*w ww .j a v a2s . co m*/ } }); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0); mSearchIconResId = a.getResourceId(R.styleable.SearchView_searchIcon, 0); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } a.recycle(); boolean focusable = true; a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); focusable = a.getBoolean(R.styleable.View_android_focusable, focusable); a.recycle(); setFocusable(focusable); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:onion.chat.MainActivity.java
private void listen() { //inform();//from ww w .j a va2 s . c om PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() == 0) { Toast.makeText(this, "Voice recognizer not present", Toast.LENGTH_SHORT).show(); } else { try { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Its Ur's"); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); } catch (Exception e) { String toSpeak = "Oops your device doesn't support Voice recognition"; Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show(); t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null); } } }
From source file:nl.hnogames.domoticz.SpeechSettingsActivity.java
private void startRecognition() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (PermissionsUtil.canAccessAudioState(this)) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName()); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); speechRecognizer.startListening(intent); listeningSpeechRecognition = true; playRecognitionAnimation();/* w ww . j a v a 2 s . c o m*/ } else { permissionHelper.request(PermissionsUtil.INITIAL_AUDIO_PERMS); } } else { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName()); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); speechRecognizer.startListening(intent); listeningSpeechRecognition = true; playRecognitionAnimation(); } }
From source file:indrora.atomic.activity.ConversationActivity.java
/** * On resume//from w w w .j a v a2 s .c om */ @Override public void onResume() { // register the receivers as early as possible, otherwise we may loose a // broadcast message channelReceiver = new ConversationReceiver(server.getId(), this); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE)); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_NEW)); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_REMOVE)); registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_TOPIC)); serverReceiver = new ServerReceiver(this); registerReceiver(serverReceiver, new IntentFilter(Broadcast.SERVER_UPDATE)); super.onResume(); // Check if speech recognition is enabled and available if (new Settings(this).isVoiceRecognitionEnabled()) { PackageManager pm = getPackageManager(); Button speechButton = (Button) findViewById(R.id.speech); List<ResolveInfo> activities = pm .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { ((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this)); speechButton.setVisibility(View.VISIBLE); } } // Start service Intent intent = new Intent(this, IRCService.class); intent.setAction(IRCService.ACTION_FOREGROUND); startService(intent); int flags = 0; if (android.os.Build.VERSION.SDK_INT > 13) { flags |= Context.BIND_ABOVE_CLIENT; flags |= Context.BIND_IMPORTANT; } bindService(intent, this, flags); // Let's be explicit about this. ((EditText) findViewById(R.id.input)).setEnabled(true); // Optimization - cache field lookup Collection<Conversation> mConversations = server.getConversations(); MessageListAdapter mAdapter; // Fill view with messages that have been buffered while paused for (Conversation conversation : mConversations) { String name = conversation.getName(); mAdapter = pagerAdapter.getItemAdapter(name); if (mAdapter != null) { mAdapter.addBulkMessages(conversation.getBuffer()); conversation.clearBuffer(); } else { // Was conversation created while we were paused? if (pagerAdapter.getPositionByName(name) == -1) { onNewConversation(name); } } // Clear new message notifications for the selected conversation if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) { Intent ackIntent = new Intent(this, IRCService.class); ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS); ackIntent.putExtra(IRCService.EXTRA_ACK_SERVERID, serverId); ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, name); startService(ackIntent); } } // Remove views for conversations that ended while we were paused int numViews = pagerAdapter.getCount(); if (numViews > mConversations.size()) { for (int i = 0; i < numViews; ++i) { if (!mConversations.contains(pagerAdapter.getItem(i))) { pagerAdapter.removeConversation(i--); --numViews; } } } // Join channel that has been selected in JoinActivity // (onActivityResult()) if (joinChannelBuffer != null) { new Thread() { @Override public void run() { binder.getService().getConnection(serverId).joinChannel(joinChannelBuffer); joinChannelBuffer = null; } }.start(); } setupColors(); setupIndicator(); openSoftKeyboard(findViewById(R.id.input)); server.setIsForeground(true); }
From source file:android.support.v7ox.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mDrawableManager = AppCompatDrawableManager.get(); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView, defStyleAttr, 0);//w w w .jav a 2s. c o m final LayoutInflater inflater = LayoutInflater.from(context); final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view); inflater.inflate(layoutResId, this, true); mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mSearchSrcTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSearchButton = (ImageView) findViewById(R.id.search_button); mGoButton = (ImageView) findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn); mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon); // Set up icons and backgrounds. mSearchPlate.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_queryBackground)); mSubmitArea.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_submitBackground)); mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon)); mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon)); mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon)); mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon); // Extract dropdown layout resource IDs for later use. mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout, R.layout.abc_search_dropdown_item_icons_2line); mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mGoButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.setOnClickListener(mOnClickListener); mSearchSrcTextView.addTextChangedListener(mTextWatcher); mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener); mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener); mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener); mSearchSrcTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); } } }); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } mDefaultQueryHint = a.getText(R.styleable.SearchView_defaultQueryHint); mQueryHint = a.getText(R.styleable.SearchView_queryHint); final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } boolean focusable = true; focusable = a.getBoolean(R.styleable.SearchView_android_focusable, focusable); setFocusable(focusable); a.recycle(); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:android.support.v7.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView, defStyleAttr, 0);//from ww w. j a v a 2s . c o m // Keep the TintManager in case we need it later mTintManager = a.getTintManager(); final LayoutInflater inflater = LayoutInflater.from(context); final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view); inflater.inflate(layoutResId, this, true); mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mSearchSrcTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSearchButton = (ImageView) findViewById(R.id.search_button); mGoButton = (ImageView) findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn); mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon); // Set up icons and backgrounds. mSearchPlate.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_queryBackground)); mSubmitArea.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_submitBackground)); mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon)); mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon)); mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon)); mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon); // Extract dropdown layout resource IDs for later use. mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout, R.layout.abc_search_dropdown_item_icons_2line); mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mGoButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.setOnClickListener(mOnClickListener); mSearchSrcTextView.addTextChangedListener(mTextWatcher); mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener); mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener); mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener); mSearchSrcTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); } } }); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } final CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } boolean focusable = true; focusable = a.getBoolean(R.styleable.SearchView_android_focusable, focusable); setFocusable(focusable); a.recycle(); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:root.magicword.MagicWord.java
private void sendRecognizeIntent() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the magic word"); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100); startActivityForResult(intent, SPEECH_REQUEST_CODE); }
From source file:org.gots.ui.NewSeedActivity.java
@Override public void onClick(View v) { newSeed.setDescriptionDiseases(descriptionDiseases.getText().toString()); newSeed.setDescriptionCultivation(descriptionEnvironment.getText().toString()); newSeed.setDescriptionHarvest(descriptionHarvest.getText().toString()); newSeed.setDescriptionGrowth(descriptionGrowth.getText().toString()); Intent intent;//from w w w. j a v a2s . c o m switch (v.getId()) { case R.id.imageBarCode: scanBarCode(); break; case R.id.buttonStock: if (validateSeed()) { new AsyncTask<Void, Integer, Void>() { @Override protected Void doInBackground(Void... params) { if (picturePath != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Bitmap bitmap = FileUtilities.decodeScaledBitmapFromSdCard(picturePath, 100, 100); bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos); byte[] bitmapdata = bos.toByteArray(); // write the bytes in file FileOutputStream fos; try { fos = new FileOutputStream(new File(gotsPrefs.getGotsExternalFileDir(), newSeed.getVariety().toLowerCase().replaceAll("\\s", ""))); fos.write(bitmapdata); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } newSeed = seedManager.createSeed(newSeed, new File(picturePath)); } else newSeed = seedManager.createSeed(newSeed, null); // seedManager.attach seedManager.addToStock(newSeed, gardenManager.getCurrentGarden()); return null; } protected void onPostExecute(Void result) { getApplicationContext().sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST)); NewSeedActivity.this.finish(); }; }.execute(); } break; case R.id.buttonModify: if (validateSeed()) { new AsyncTask<Void, Integer, Void>() { @Override protected Void doInBackground(Void... params) { seedManager.updateSeed(newSeed); return null; } protected void onPostExecute(Void result) { getApplicationContext().sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST)); NewSeedActivity.this.finish(); }; }.execute(); } break; case R.id.IdSeedDescriptionCultureVoice: intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); startActivityForResult(intent, REQUEST_GROWTH); break; case R.id.IdSeedDescriptionEnnemiVoice: intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); startActivityForResult(intent, REQUEST_DISEASES); break; case R.id.IdSeedDescriptionEnvironmentVoice: intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); startActivityForResult(intent, REQUEST_ENVIRONMENT); break; case R.id.IdSeedDescriptionHarvestVoice: intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); startActivityForResult(intent, REQUEST_HARVEST); break; // case R.id.buttonCatalogue: // if (validateSeed()) { // seedManager.createSeed(newSeed); // finish(); // } // break; default: break; } }
From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealSearchFragment.java
private void promptSpeechInput() { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0); Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say Something"); try {/*from w w w . j a v a 2 s . co m*/ startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); } catch (ActivityNotFoundException a) { Toast.makeText(getActivity().getApplicationContext(), "Not Supported", Toast.LENGTH_SHORT).show(); } }
From source file:com.meetingninja.csse.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (drawerToggle.onOptionsItemSelected(item)) { return true; }/*from w ww. j a v a2 s . c o m*/ // Handle other action bar items... switch (item.getItemId()) { case R.id.action_refresh: switch (DrawerLabel.values()[session.getPage()]) { case MEETINGS: Toast.makeText(this, "Refreshing Meetings", Toast.LENGTH_SHORT).show(); frag_meetings.fetchMeetings(); // frag_meetings.populateList(); return true; case NOTES: Toast.makeText(this, "Refreshing Notes", Toast.LENGTH_SHORT).show(); // notesFrag.fetchNotes(); frag_notes.populateList(); return true; default: return super.onOptionsItemSelected(item); } case R.id.action_new_meeting: frag_meetings.editMeeting(null); return true; case R.id.action_new_note: Intent createNote = new Intent(this, EditNoteActivity.class); createNote.putExtra(Note.CREATE_NOTE, true); startActivityForResult(createNote, 3); return true; case R.id.action_logout: logout(); return true; case R.id.action_settings: return true; case R.id.action_speak: Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US"); i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Go to..."); try { startActivityForResult(i, VOICE_RECOGNITION_REQUEST_CODE); } catch (Exception e) { Toast.makeText(this, "Error initializing speech to text engine.", Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } }