当前位置:   article > 正文

Android离线语音识别(SpeechRecognizer、PocketSphinx)_android speechrecognizer

android speechrecognizer

最近有开发语音识别功能的需求,但是因为各种原因(主要是收费)不能用国内大厂(百度,讯飞)已有的sdk,于是在网上搜了很多android离线的语音识别,主要有两种:

1.android自带的SpeechRecognizer,但是试了好几种手机,都是提示没有语音识别服务,最终无果,没办法解决,部分代码如下:

  1. private SpeechRecognizer mSpeechRecognizer;
  2. mSpeechRecognizer=SpeechRecognizer.createSpeechRecognizer(this);
  3. mSpeechRecognizer.setRecognitionListener(this);
  4. public void doSpeechRecognition(Context context){
  5. if(isRecognitionAvailable(context)){
  6. Intent recognitionIntent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  7. recognitionIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true);
  8. recognitionIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"zh-CN");
  9. this.mSpeechRecognizer.startListening(recognitionIntent);
  10. }else{
  11. Toast.makeText(context,"没有语音识别服务",Toast.LENGTH_SHORT).show();
  12. }
  13. }
  14. @Override
  15. public void onReadyForSpeech(Bundle params) {
  16. Log.i("SpeechRecognition","onReadyForSpeech");
  17. }
  18. @Override
  19. public void onBeginningOfSpeech() {
  20. Log.i("SpeechRecognition","onBeginningOfSpeech");
  21. }
  22. @Override
  23. public void onRmsChanged(float rmsdB) {
  24. Log.i("SpeechRecognition","onRmsChanged");
  25. }
  26. @Override
  27. public void onBufferReceived(byte[] buffer) {
  28. Log.i("SpeechRecognition","onBufferReceived");
  29. }
  30. @Override
  31. public void onEndOfSpeech() {
  32. Log.i("SpeechRecognition","onEndOfSpeech");
  33. }
  34. @Override
  35. public void onError(int error) {
  36. Log.i("SpeechRecognition","onError");
  37. }
  38. @Override
  39. public void onResults(Bundle results) {
  40. ArrayList<String> partialResults=results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
  41. if(partialResults!=null && partialResults.size()>0) {
  42. String bestResult = partialResults.get(0);
  43. Log.i("SpeechRecognition","onResults bestResult="+bestResult);
  44. //result.setText(bestResult);
  45. }
  46. }

2.PocketSphinx,不多说,目前感觉是唯一的救命稻草,基本能用,单个短语容易误识别

参考文章:https://www.cnblogs.com/elecdog/p/7235235.html

https://www.jianshu.com/p/82ffb90cc463

参考demo如下:https://download.csdn.net/download/android_xc/12274142

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/327428
推荐阅读
相关标签
  

闽ICP备14008679号