0

I'm new to Android, and I have to do a project, in which I need to create an app which can be used to get voice commands. I need to record user's voice, save it as audio file then convert into text or just convert it directly to text file without saving audio file.

This is what I've been done so far,

public class VoiceRecognitionDemo extends Activity{

    private static final int REQUEST_CODE = 1234;
    private ListView wordsList;

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

        Button speakButton = (Button) findViewById(R.id.speakButton);

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

        // Disable button if no recognition service is present
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        if (activities.size() == 0)
        {
            speakButton.setEnabled(false);
            speakButton.setText("Recognizer not present");
        }
    }

    /**
     * Handle the action of the button being clicked
     */
    public void speakButtonClicked(View v)
    {
        startVoiceRecognitionActivity();
    }

    /**
     * Fire an intent to start the voice 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, "Voice recognition Demo...");
        startActivityForResult(intent, REQUEST_CODE);
    }

    /**
     * Handle the results from the voice recognition activity.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
        {
            // Populate the wordsList with the String values the recognition engine thought it heard
            ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    matches));
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

I need to sort this array to extract certain keywords to trigger an action. How do I trigger certain action (example - initiate a call on phrases call, talk to)?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vishwa
  • 801
  • 11
  • 26
  • 1
    Building Siri or Google Voice might be a bit on the difficult side of things. – ifly6 Jul 03 '16 at 07:24
  • i know :( but its the thing i have to do,not sooo advanced like them.but very simple one – Vishwa Jul 03 '16 at 09:00
  • 1
    You can start from here - speech to text tutorial: http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/ – MorZa Jul 03 '16 at 10:06
  • i tried that one.but it didt run successfully on my phone or my buddys' phones.i dont know whats wrong.sometimes it even fails to install.thanks for the link MorZa – Vishwa Jul 03 '16 at 12:57

1 Answers1

1

You can recognize voice-to-text using the Nuance SDK. It's a cross-platform SDK with more than 40 languages supported. This SDK isn't free, but you can use a test key which lives 30 days.

You can send an audio file or stream to the Nuance server. In response you will get a text string. Then you can realize your own logic of getting keywords and commands.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MatWay
  • 66
  • 9
  • Thanks matway for your help. i checked nuance.but its little bit difficult for me.anyway can i use google's own pre build thingy on android?please help if you know – Vishwa Jul 03 '16 at 09:06
  • Hm... I used only nuance sdk, but after some search i found two interested answers for your problem: [first](http://stackoverflow.com/questions/4975443/is-there-a-way-to-use-the-speechrecognizer-api-directly-for-speech-input) and [second](http://stackoverflow.com/questions/4559930/speechrecognizer-causes-anr-i-need-help-with-android-speech-api). I have no time to test that code by myself, but it looks simple and i hope you can use native google speach recognition by that way. – MatWay Jul 03 '16 at 10:10
  • many thanks for your help.i'll give them a try :) and will come back if i get any problems.thanks for all help – Vishwa Jul 03 '16 at 14:09