• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps android studio

maazit

Lurker
this is my code in speech to text app ,and i have error in "R"
package translation.speech.maazsalahit.com.speechtranslation;

import java.util.ArrayList;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

protected static final int RESULT_SPEECH = 1;

private Button btnSpeak;
private TextView txtText;

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

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

btnSpeak = (Button) findViewById(R.id.speak);

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;
}

}
}
}
 
Back
Top Bottom