4

Hi i need help with speech to text conversion in android, ive been googling the topic for an hour now and every help i find shows me how to convert text into speech and not the other way arround,

http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html

the two links above also show me how to convert text into speech, im basically building an app that records whatever the user speeks and then converts it into text, im having problems converting the audio

please tell me if its even possible and if it is then can you please give me a link,

Umer Hassam
  • 1,332
  • 5
  • 23
  • 42

2 Answers2

2

User the RecognizerIntent to use speech input in your application. You can have a look at the sample code VoiceRecognition from Google.

Chris
  • 7,864
  • 1
  • 27
  • 38
  • Hi Thanks for the reply it was great help however can you do me one more favor, i tried to run the code and created an xml with appropriate id's i even set the permissions for AUDIO_RECORD but when i run the app the button has text RECOGNIZER NOT PRESENT on it, which means im surely missing some hardware permission or something because text to speech was working fine earlier.. any idea what it might be??? – Umer Hassam Mar 09 '11 at 23:06
  • @umer: The Intent makes use of any speech recognition service available on the device. Make sure "Voice Search" (from Android market : https://market.android.com/details?id=com.google.android.voicesearch) is installed on your device. – Chris Mar 09 '11 at 23:44
  • aah, Thanks so much for your help.. ill download and install it first thing in the morning :D its 5:30am in the morning and my eyes are burning.. thanks again. – Umer Hassam Mar 10 '11 at 00:37
  • **VoiceRecognition** Link is redirecting to wrong url – Pratik Butani Oct 08 '18 at 05:59
  • 1
    @PratikButani looks like google have removed/deprecated the demo. Googling around lead to this example https://www.developer.com/ws/android/programming/exploring-the-android-speech-api-for-voice-recognition.html – angryITguy Jan 22 '19 at 00:24
0

This is the code

    public class MainActivity extends Activity {

    protected static final int RESULT_SPEECH = 1;

    private ImageButton btnSpeak;
    private TextView txtText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtText = (TextView) findViewById(R.id.txtText);

        btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);

        btnSpeak.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(
                        RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

                try {
                    startActivityForResult(intent, RESULT_SPEECH);
                    txtText.setText("");
                } catch (ActivityNotFoundException a) {
                    Toast t = Toast.makeText(getApplicationContext(),
                            "Opps! Your device doesn't support Speech to Text",
                            Toast.LENGTH_SHORT);
                    t.show();
                }
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
        case RESULT_SPEECH: {
            if (resultCode == RESULT_OK && null != data) {

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

                txtText.setText(text.get(0));
            }
            break;
        }

        }
    }
}
Nischitha s
  • 1
  • 4
  • 9