3 回答

TA貢獻1803條經(jīng)驗 獲得超3個贊
據(jù)我所知,仍然沒有辦法直接將音頻剪輯發(fā)送給Google進行轉(zhuǎn)錄。但是,F(xiàn)royo(API級別8)引入了SpeechRecognizer類,該類提供對語音識別服務的直接訪問。因此,例如,您可以開始播放音頻剪輯,并讓“活動”啟動語音識別器在后臺監(jiān)聽,這將在完成后將結(jié)果返回到用戶定義的監(jiān)聽器回調(diào)方法。
以下示例代碼應在Activity中定義,因為SpeechRecognizer的方法必須在主應用程序線程中運行。另外,您還需要將RECORD_AUDIO權(quán)限添加到您的AndroidManifest.xml中。
boolean available = SpeechRecognizer.isRecognitionAvailable(this);
if (available) {
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new RecognitionListener() {
@Override
public void onResults(Bundle results) {
// process results here
}
// define your other overloaded listener methods here
});
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// the following appears to be a requirement, but can be a "dummy" value
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.dummy");
// define any other intent extras you want
// start playback of audio clip here
// this will start the speech recognizer service in the background
// without starting a separate activity
sr.startListening(intent);
}
您還可以通過擴展RecognitionService來定義自己的語音識別服務,但這超出了此答案的范圍:)
- 3 回答
- 0 關(guān)注
- 478 瀏覽
添加回答
舉報