我正致力于语音识别,我需要用多种语言来完成此任务。多种语言的文本语音
什么,我到底要如果印地文或任何其他语言的用户对话,则需要显示它在文本视图。 现在它的英文作品完美无缺。
什么,我需要做的是多语言,每用户的选择..
请帮助我,谢谢你..
这里是我的代码
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