本文介绍了Android 中的离线语音识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 StackOverFlow 上搜索了很多关于这个问题,但线程已经超过 3 年了.
I searched a lot on StackOverFlow for this Problem but the Threads are older than 3 years old.
我实现了需要 Internet 连接的 Google 语音识别
.搜索如何使用 Offline Voice Recognition
没有成功.
I implemented the Google Voice Recognition
which requires a Internet Connection. Searching how i can use the Offline Voice Recognition
brought no success.
现在离线时是否可以使用语音识别
?
Is it now available to use the Voice Recognition
when you're offline?
我的代码直到:
speechStartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
promtSpeechInput();
}
});
private void promtSpeechInput() {
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,
"Recording...");
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Language not supported", Toast.LENGTH_SHORT).show();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CAMERA_PIC_REQUEST: {
try {
Bitmap image = (Bitmap) data.getExtras().get("data");
ImageView imageView = (ImageView) findViewById(R.id.taskPhotoImage);
imageView.setImageBitmap(image);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
case REQ_CODE_SPEECH_INPUT: {
if(resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
speechToTextField.setText(speechToTextField.getText()+" " +result.get(0));
}
break;
}
}
}
国王问候
推荐答案
与 Google 无关.
Not with Google.
您必须使用另一种解决方案,例如 CMU Sphinx.在这里查看:Android:不使用谷歌服务器的语音识别
You have to use another solution like CMU Sphinx.Check here : Android: Speech Recognition without using google server
这篇关于Android 中的离线语音识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!