PDA

View Full Version : مشکل در Recognizer Intent



masoud_urmia
جمعه 05 مهر 1392, 12:05 عصر
سلام دوستان وقتی پروژه تبدیل گفتار به متن رو اجرا می کنم خطای Force Close می گیرم اینم کدش :

public class MainActivity extends Activity {
private static final int RECOGNIZER_EXAMPLE = 1001;
private TextView tv;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

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

//setup button listener
Button startButton = (Button) findViewById(R.id.rec);
startButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// RecognizerIntent prompts for speech and returns text
Intent intent =
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MO DEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Say a word or phrase\nthen it will appear on the screen.");
startActivityForResult(intent, RECOGNIZER_EXAMPLE);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RECOGNIZER_EXAMPLE && resultCode == RESULT_OK) {
// returned data is a list of matches to the speech input
ArrayList<String> result =
data.getStringArrayListExtra(RecognizerIntent.EXTR A_RESULTS);

//display on screen
tv.setText(result.toString());
}

super.onActivityResult(requestCode, resultCode, data);
}
}