我正致力於語音識別,我需要用多種語言來完成此任務。多種語言的文本語音
什麼,我到底要如果印地文或任何其他語言的用戶對話,則需要顯示它在文本視圖。 現在它的英文作品完美無缺。
什麼,我需要做的是多語言,每用戶的選擇..
請幫助我,謝謝你..
這裏是我的代碼
public class MainActivity extends AppCompatActivity {
private static final int REQ_CODE_SPEECH_INPUT = 100;
private TextView mVoiceInputTv;
private ImageButton mSpeakBtn;
private TextToSpeech t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mVoiceInputTv = (TextView) findViewById(R.id.voiceInput);
mSpeakBtn = (ImageButton) findViewById(R.id.btnSpeak);
mSpeakBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startVoiceInput();
}
});
}
private void startVoiceInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Hello, How can I help you?");
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
}
catch (ActivityNotFoundException a) {
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if(userlanguage.equals("English")){
mVoiceInputTv.setText(result.get(0));
}
else if(userlanguage.equals("Hindi")){
face = Typeface.createFromAsset(getAssets(),"fonts/DroidHindi.ttf");
mVoiceInputTv.setTypeface(face);
mVoiceInputTv.setText(result.get(0));
}
else if(userlanguage.equals("Marathi")){
face = Typeface.createFromAsset(getAssets(),"fonts/Marathi.ttf");
mVoiceInputTv.setTypeface(face);
mVoiceInputTv.setText(result.get(0));
}
else if(userlanguage.equals("Gujarati")){
face = Typeface.createFromAsset(getAssets(),"fonts/Gujarati.ttf");
mVoiceInputTv.setTypeface(face);
mVoiceInputTv.setText(result.get(0));
}
}
break;
}
}
}
}
我不喜歡的東西,但我沒有不力這是正確的方式或不? – pratikSonawane