Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:40:31+00:00 2026-06-08T06:40:31+00:00

I am currently working on an app and I need to be able to

  • 0

I am currently working on an app and I need to be able to have the user control the app with nothing but their voice if necessary. I got a copy of some speech recognition code that apparently comes from android and I tried using it in my app. The code itself appears fairly simple but I need help understanding a few parts and implementing it on the app. I have ran the app on an android device and when I use the speech I get a list of phrases I possibly said. I want to be able to set up and activity where if one of the results is “close app” for example it will close the app. I thought I could set this up by doing an if statement for the results of the voice recognizer. Such as if results == close app then run the activity close. I don’t have any of this set up because I’m not sure how to code it exactly but I thought some of you would have some ideas.

package com.example.com.proto1;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;


    /**
     * Sample code that invokes the speech recognition intent API.
     */
    public class VoiceRecognition extends Activity implements OnClickListener {

        private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

        private ListView mList;

        /**
         * Called with the activity is first created.
         */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            // Inflate our UI from its XML layout description.
            setContentView(R.layout.voice_recognition);

            // Get display items for later interaction
            Button speakButton = (Button) findViewById(R.id.btn_speak);

            mList = (ListView) findViewById(R.id.list);

            // Check to see if a recognition activity is present
            PackageManager pm = getPackageManager();
            List<ResolveInfo> activities = pm.queryIntentActivities(
                    new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
            if (activities.size() != 0) {
                speakButton.setOnClickListener(this);
            } else {
                speakButton.setEnabled(false);
                speakButton.setText("Recognizer not present");
            }
        }

        /**
         * Handle the click on the start recognition button.
         */
        public void onClick(View v) {
            if (v.getId() == R.id.btn_speak) {
                startVoiceRecognitionActivity();
            }
        }

        /**
         * Fire an intent to start the speech recognition activity.
         */
        private void startVoiceRecognitionActivity() {
            Intent 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, VOICE_RECOGNITION_REQUEST_CODE);
        }

        /**
         * Handle the results from the recognition activity.
         */
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
                // Fill the list view with the strings the recognizer thought it could have heard
                ArrayList<String> matches = data.getStringArrayListExtra(
                        RecognizerIntent.EXTRA_RESULTS);
                mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                        matches));
            }

            super.onActivityResult(requestCode, resultCode, data);

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:40:34+00:00Added an answer on June 8, 2026 at 6:40 am

    This is results you have received from voice recognition activity:

    ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    

    matches is a list of possible texts that you have pronounced. If you want to close your app when some magic phrase was said you need something like this:

    if (matches.contains("close")) {
         finish();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on an app, where I need to insert contacts into
I'm currently working on an app that lets the user choose an MP3 audio
I'm currently working on an app that allows the user to draw pixelated images
I'm currently working on a reasonably simple MVC app which allows the user to
I'm working on a Titanium app (currently targeted for iPhone deployment, but ultimately intended
Currently working with Oracle, but will also need a solution for MS SQL. I
I'm currently working on a Silverlight app and need to convert XML data into
I have resque-scheduler working fine in a rails app. Now I need to be
Working with ajax on a rails 3.1 app, i need to be able to
I'm currently working on an app that is being created using Ironspeed Designer. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.