'simultaneously record audio and convert to text

I have developed an app that records an audio for a particular duration, another one which uses web to convert speech to text. Is it possible that both the things can be done simultaneously? I mean to record an audio and convert the speech available in that recorded audio file to text?



Solution 1:[1]

The way you're doing this might not be very accurate, as there are many different suggestions to the voice input. But you can give it a hit.
By what i understood, you should run audio in background service and start voice detection.
For background service this is how you use them. You can see a full app here too.
For voice recognition, you can refer here.

This is how you create a service.
Better to put your media code in service. It is best way to play media in background.

public class serv extends Service{

    MediaPlayer mp;
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
    public void onCreate()
    {   
        mp = MediaPlayer.create(this, R.raw.b);
        mp.setLooping(false);
    }
    public void onDestroy()
    {       
        mp.stop();
    }
    public void onStart(Intent intent,int startid){

        Log.d(tag, "On start");
        mp.start();
    }
}

where raw is folder created in resources. and R.raw.b is an mp3 file.
Call this service just before you fire this intent.

/**
 * 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);
}  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salmaan