【发布时间】:2019-07-16 00:12:43
【问题描述】:
我想创建一个应用程序,在单击按钮时更改默认的 android 系统文本到语音转换语言。为什么我需要那个?因为我正在为盲人使用这个应用程序。因此,对于注册和登录,我需要英语,但是当他们进入应用程序时,语言应该不同(孟加拉语)。
那么,如果有人可以帮助我吗?告诉我。
谢谢
【问题讨论】:
标签: android text-to-speech voice-recognition
我想创建一个应用程序,在单击按钮时更改默认的 android 系统文本到语音转换语言。为什么我需要那个?因为我正在为盲人使用这个应用程序。因此,对于注册和登录,我需要英语,但是当他们进入应用程序时,语言应该不同(孟加拉语)。
那么,如果有人可以帮助我吗?告诉我。
谢谢
【问题讨论】:
标签: android text-to-speech voice-recognition
您可以使用 Google Cloud Speech API。 Google Cloud Speech-to-Text 使开发人员能够通过在易于使用的 API 中应用强大的神经网络模型将音频转换为文本
请注意以下几点
详情:https://cloud.google.com/speech-to-text/
价格:https://cloud.google.com/speech-to-text/pricing
例子:
public class MainActivity extends Activity {
private TextView txtSpeechInput;
private ImageButton btnSpeak;
private final int REQ_CODE_SPEECH_INPUT = 100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtSpeechInput = (TextView) findViewById(R.id.txtSpeechInput);
btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
// hide the action bar
getActionBar().hide();
btnSpeak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
promptSpeechInput();
}
});
}
// Showing google speech input dialog
private void promptSpeechInput() {
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,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
//Receiving speech input
@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);
txtSpeechInput.setText(result.get(0));
}
break;
}
}
}
}
【讨论】: