0% found this document useful (0 votes)
14 views2 pages

SpeechToText - JAVA

This document contains the Java code for an Android application that implements speech-to-text functionality. The MainActivity class initializes a speech recognition intent when a button is clicked and displays the recognized text in a TextView. It also includes menu options for additional settings, handling cases where the device does not support speech recognition.

Uploaded by

irfanandessa1012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

SpeechToText - JAVA

This document contains the Java code for an Android application that implements speech-to-text functionality. The MainActivity class initializes a speech recognition intent when a button is clicked and displays the recognized text in a TextView. It also includes menu options for additional settings, handling cases where the device does not support speech recognition.

Uploaded by

irfanandessa1012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package [Link].

speechtotext;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends Activity {

protected static final int RESULT_SPEECH = 1;

private ImageButton btnSpeak;


private TextView txtText;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

txtText = (TextView) findViewById([Link]);

btnSpeak = (ImageButton) findViewById([Link]);

[Link](new [Link]() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Intent intent = new Intent(


RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

[Link](RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-
US");

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

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate([Link], menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
}

You might also like