谷歌語音

- 在谷歌應用市場安裝好谷歌語音搜索

 

機器產生的替代文字:语音禮紊PrometheusInteractivE

  •  
  •  
  • 下載語音離線包

 

 

  • 調用谷歌語音API

 

-判斷是否支持谷歌語音識別功能(很多墻內閹割機用不了)

    啟動語音識別功能   另一種方法是 採用startActitvityForResult(大同小異,自行搜索)

if(SpeechRecognizer.isRecognitionAvailable(getActivity())){

if(intent==null){

intent=newIntent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

//設置支持過程中可用的識別結果

intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true);

//語言模型

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

//用於語音搜索的額外密鑰

intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,getActivity().getPackageName());

//最大結果數

intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);

sr.startListening(intent);

}else{

if(sr!=null){

sr.startListening(intent);

}

}

 

 

//提供語音識別服務的類

privateSpeechRecognizersr;

 

//實例化

sr=SpeechRecognizer.createSpeechRecognizer(getActivity());

//設置監聽

sr.setRecognitionListener(newListener());

 

 

 

//語音監聽

classListenerimplementsRecognitionListener{

 

@Override

publicvoidonReadyForSpeech(Bundl eparams){

//endpointer 準備好讓用戶開始說話

}

@Override

publicvoidonBeginningOfSpeech(){

//開始說話

}

@Override

publicvoidonRmsChanged(floatrmsdB){

//音頻聲級更改時調用.不保證一定會成功調用

}

@Override

publicvoidonBufferReceived(byte[]buffer){

//收到更多的聲音時,不保證一定調用

}

@Override

publicvoidonEndOfSpeech(){

//結束說話

}

@Override

publicvoidonError(interror){

//異常

}

@Override

publicvoidonResults(Bundleresults){

//最終結果  

}

@Override

publicvoidonPartialResults(BundlepartialResults){

//intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true);設置后這裡就可以獲取過程中的識別結果

}

@Override

publicvoidonEvent(inteventType,Bundleparams){

//保留,用於添加未來事件

}

}

 

 

 

ACTION_RECOGNIZE_SPEECH

Starts an activity that will prompt the user for speech and send it through a speech recognizer.

 

EXTRA_LANGUAGE

Optional IETF language tag (as defined by BCP 47), for example "en-US".

 

EXTRA_LANGUAGE_MODEL

Informs the recognizer which speech model to prefer when performing ACTION_RECOGNIZE_SPEECH.

 

EXTRA_PREFER_OFFLINE

Optional boolean, to be used with ACTION_RECOGNIZE_SPEECH,ACTION_VOICE_SEARCH_HANDS_FREE, ACTION_WEB_SEARCH to indicate whether to only use an offline speech recognition engine.

 

 

RESULT_NETWORK_ERROR

Result code returned when a network error was encountered

 

等等

 

 

 

 

以下鏈接非常詳細的介紹了各API的用法

https://developer.android.com/reference/android/speech/RecognitionListener

https://developer.android.com/reference/android/speech/RecognizerIntent

https://developer.android.com/reference/android/speech/SpeechRecognizer

 

 

百度的時候千篇一律 RecognizerIntent的講解很少最後還是看的官方文檔

 

掌握科學上網很重要,官方文檔講解非常全面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值