[英]Offline Speech Recognition in Android
我在StackOverFlow上搜索了很多有关此问题的内容,但是这些线程的使用时间已超过3年。
我实现了需要互联网连接的Google Voice Recognition
。 搜索如何使用Offline Voice Recognition
没有成功。
现在可以离线使用Voice Recognition
吗?
我的代码到目前为止:
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。
您必须使用另一种解决方案,例如CMU Sphinx。 在这里检查: Android:不使用Google服务器的语音识别
实际上,您可以脱机使用SpeechRecognizer。
问题在于,如果不使用循环,它就不会连续,并且由于恒定的蜂鸣声,使用SpeechRecognizer进行循环绝对令人讨厌。 蜂鸣声周围有多种方法,但是大多数都使蜂鸣声静音,并且所有声音都与之相同。
在步骤中还提到了,您还必须下载“ Google语音输入”及其语言,这会占用更多存储空间。 总体而言,您可以脱机使用SpeechRecognizer,但这是一个很大的麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.