0
我似乎無法在手機上運行語音識別器。應用程序instals和按鈕正在返回它需要返回的內容,但實際的語音識別器不會返回到Speech的起始位置等等...這是我的代碼,希望這是一個簡單的修復。我運行在顯示erros(Trace:無法打開,沒有這樣的目錄)和ActivityManager的Galaxy s3上:Warning:警告:Activity沒有啓動,它的當前任務已經提前。可能是權限問題。任何幫助將是偉大的!無法運行Speechrecognizer Android
public class MainActivity extends Activity implements OnClickListener {
ListView lv;
private SpeechRecognizer mSpeechRecognizer;
private Intent mSpeechRecognizerIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView)findViewById(R.id.lvVoiceReturn);
Button b= (Button)findViewById(R.id.bVoice);
b.setOnClickListener(this);
boolean available = SpeechRecognizer.isRecognitionAvailable(this);
Log.d("Speech", "available = " + available);
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(new SpeechListener());
mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("speech", "button active");
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
}
private class SpeechListener implements RecognitionListener {
@Override
public void onBeginningOfSpeech() {
Log.d("Speech", "onBeginningOfSpeech");
}
@Override
public void onBufferReceived(byte[] buffer) {
Log.d("Speech", "onBufferReceived");
}
@Override
public void onEndOfSpeech() {
Log.d("Speech", "onEndOfSpeech");
}
@Override
public void onError(int error) {
Log.d("Speech", "onError");
}
@Override
public void onEvent(int eventType, Bundle params) {
Log.d("Speech", "onEvent");
}
@Override
public void onPartialResults(Bundle partialResults) {
Log.d("Speech", "onPartialResults");
}
@Override
public void onReadyForSpeech(Bundle params) {
Log.d("Speech", "onReadyForSpeech");
}
@Override
public void onResults(Bundle results) {
Log.d("Speech", "results");
}
@Override
public void onRmsChanged(float rmsdB) {
//Log.d("Speech", "onRmsChanged");
}
}
}
這裏是我的清單
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.speech.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
什麼是操作系統版本後添加以下的
onCreate
? ICS還是JB?還張貼您的清單 – 2013-05-03 03:08:13我在JB 4.2.2 – 2013-05-03 03:14:29
添加了用戶權限,遺憾的是仍然沒有收到任何語音輸入方式。我仍然得到這些錯誤。我不知道現在發生了什麼。真的只是需要幫助這一個很糟糕。 – 2013-05-03 03:30:37