Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 语音识别中的错误8_Android - Fatal编程技术网

Android 语音识别中的错误8

Android 语音识别中的错误8,android,Android,此代码在语音识别中给出错误8,即使在我第一次启动应用程序时也是如此..识别器可能正忙,但至少应工作1次..plz帮助 此应用程序仅用于检测语音并给出结果 包装费用 import android.app.Activity; import android.app.Dialog; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import a

此代码在语音识别中给出错误8,即使在我第一次启动应用程序时也是如此..识别器可能正忙,但至少应工作1次..plz帮助

此应用程序仅用于检测语音并给出结果

包装费用

import android.app.Activity;
import android.app.Dialog;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;




public class ExpenseAppActivity extends Activity {
    /** Called when the activity is first created. */
     private SpeechRecognizer sr,sr2;
     Button add;
     String tag="events";
     ListView modeList;
     AlertDialog.Builder builder1;
     int f;
     Button view;
       private static final String TAG = "MyStt3Activity";
       //AlertDialog.Builder builder;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.d("rahul","in on create event");
        Log.d("rahul","lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll");
        modeList= new ListView(this);
        builder1 = new AlertDialog.Builder(this);
        SQLiteAdapter mySQLiteAdapter;
        mySQLiteAdapter= new SQLiteAdapter(this);
        mySQLiteAdapter.openToWrite();
        f=0;
        mySQLiteAdapter.close();
        System.out.println("1");
         add=(Button)findViewById(R.id.add);
        System.out.println("2");
         view=(Button)findViewById(R.id.view);
        System.out.println("3");
        Button others=(Button)findViewById(R.id.others);
        System.out.println("4");

        sr = SpeechRecognizer.createSpeechRecognizer(this);   


        sr.setRecognitionListener(new listener());  


        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");

        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); 
             sr.startListening(intent);
             Log.i("111111","11111111");




        add.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                //sr.cancel();

                Intent myIntent = new Intent(ExpenseAppActivity.this,
                        Add.class);

                ExpenseAppActivity.this.startActivity(myIntent);

            }
        });

    view.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent myIntent = new Intent(ExpenseAppActivity.this,
                        ViewDetails.class);

                ExpenseAppActivity.this.startActivity(myIntent);

            }
        });

        others.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent myIntent = new Intent(ExpenseAppActivity.this,
                        Others.class);

                ExpenseAppActivity.this.startActivity(myIntent);

            }
        });





      }

    public void onStart()
      {
          super.onStart();
          Log.d(tag,"In the onStart() event");




      }

    /* public void onResume()
      {
          super.onResume();

          Log.d(tag,"In the onResume() event");
      }*/
     public void onStop()
      {
          super.onStop();
          Log.d(tag,"In the onStop() eventttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt");
          sr.stopListening();
          sr.destroy();
      }
     public void onPause()
      {
          super.onPause();
          Log.d(tag,"In the onPause() eventttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt");
          sr.stopListening();
          sr.destroy();

      }


     public void onRestart()
      {
          super.onRestart();
          Log.d(tag,"In the onRestart() event");


          sr = SpeechRecognizer.createSpeechRecognizer(this);   


            sr.setRecognitionListener(new listener());  

            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
            intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");

            intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); 
                 sr.startListening(intent);
                 Log.i("111111","11111111");
      }
     public void onDestroy()
      {
          super.onDestroy();
          Log.d(tag,"In the onDestroy() event");
      }




    class listener implements RecognitionListener          
    {
             public void onReadyForSpeech(Bundle params)
             {
                      Log.d(TAG, "onReadyForSpeech");
                     // mText5.setText("hi");
             }
             public void onBeginningOfSpeech()
             {
                      Log.d(TAG, "onBeginningOfSpeech");
                      //mText2.setText("1");
             }
             public void onRmsChanged(float rmsdB)
             {
                      Log.d(TAG, "onRmsChanged");
                      //mText3.setText("2");
             }
             public void onBufferReceived(byte[] buffer)
             {
                      Log.d(TAG, "onBufferReceived");
                      //mText4.setText("3");
             }
             public void onEndOfSpeech()
             {
                      Log.d(TAG, "onEndofSpeech");
             }
             public void onError(int error)
             {
                      Log.d(TAG,  "error " +  error);
                      add.setText("error " + error);
                      if(error==8)
                      {
                           func();  
                      }
             }
             public void onResults(Bundle results)                   
             {
                      String str = new String();

                      Log.d(TAG, "onResults " + results);
                      ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                      final String dat[]=new String[data.size()];
                      for (int i = 0; i < data.size(); i++)
                      {


                                Log.d(TAG, "result " + data.get(i));
                                dat[i]=(String) data.get(i);
                                str += data.get(i);
                      }

                      for(int i=0;i<data.size();i++)
                      {
                          if(dat[i].equalsIgnoreCase("add")|| dat[i].equalsIgnoreCase("view")|| dat[i].equalsIgnoreCase("others"))
                          {
                              f=1;
                              break;
                          }
                          else
                          {
                              f=0;
                          }
                      }

                      if(f==0)
                      {
                          func();
                          view.setText(Integer.toString(f));
                      }


                      for(int i=0;i<data.size();i++)
                      {
                          if(dat[i].equalsIgnoreCase("add"))
                          {
                              Intent myIntent = new Intent(ExpenseAppActivity.this,
                                    Add.class);

                            ExpenseAppActivity.this.startActivity(myIntent);

                          }

                          else if(dat[i].equalsIgnoreCase("view"))
                          {
                              Intent myIntent = new Intent(ExpenseAppActivity.this,
                                    ViewDetails.class);

                            ExpenseAppActivity.this.startActivity(myIntent);
                          }
                      }


                    // func(dat);
                     // mText.setText("results: "+String.valueOf(data.size()));  
                     /* builder.setTitle("Pick a color");

                     builder.setItems(dat, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int item) {
                                Toast.makeText(getApplicationContext(), dat[item], Toast.LENGTH_SHORT).show();
                            }
                        });*/
                        //AlertDialog alert = builder.create();
                      add.setText("results: "+str);  
                      //mText2.setText(dat[0]);
             }
             public void onPartialResults(Bundle partialResults)
             {
                      Log.d(TAG, "onPartialResults");
             }
             public void onEvent(int eventType, Bundle params)
             {
                      Log.d(TAG, "onEvent " + eventType);
             }



}

   /* void func(String dat[])
    {
         ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1,dat);

   Log.d("rahul","1");
         modeList.setAdapter(modeAdapter);
Log.d("rahul","2");
        builder1.setView(modeList);
        Log.d("rahul","3");
        final Dialog dialog = builder1.create();

        dialog.show();
    }*/

   void func()
    {
         sr2 = SpeechRecognizer.createSpeechRecognizer(this);   


         sr2.setRecognitionListener(new listener());  

         Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        
         intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
         intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");

         intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); 
              sr2.startListening(intent);
              Log.i("111111","11111111");

    }



}
导入android.app.Activity;
导入android.app.Dialog;
导入android.app.AlertDialog;
导入android.content.DialogInterface;
导入android.content.Intent;
导入android.os.Bundle;
导入android.speech.RecognitionListener;
导入android.speech.RecognizerIntent;
导入android.SpeechRecognizer;
导入android.util.Log;
导入android.view.view;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.ListView;
导入android.widget.TextView;
导入android.widget.Toast;
导入java.text.DateFormat;
导入java.util.ArrayList;
导入java.util.Date;
公共类费用活动扩展活动{
/**在首次创建活动时调用*/
私人语音识别器sr,sr2;
按钮添加;
String tag=“事件”;
ListView建模师;
AlertDialog.builder1;
int f;
按钮视图;
私有静态最终字符串TAG=“MyStt3Activity”;
//AlertDialog.Builder;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(“rahul”,“在创建事件中”);
Log.d(“rahul”、“llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll;
modeList=新列表视图(此);
builder1=新建AlertDialog.Builder(此);
SQLiteAdapter-mySQLiteAdapter;
mySQLiteAdapter=新的SQLiteAdapter(此);
mySQLiteAdapter.openToWrite();
f=0;
mySQLiteAdapter.close();
系统输出打印项次(“1”);
add=(按钮)findViewById(R.id.add);
系统输出打印项次(“2”);
视图=(按钮)findViewById(R.id.view);
系统输出打印项次(“3”);
按钮其他=(按钮)findViewById(R.id.others);
系统输出打印项次(“4”);
sr=SpeechRecognizer.createSpeechRecognizer(此);
sr.setRecognitionListener(新的listener());
意向意向=新意向(识别意向、行动、识别言语);
intent.putExtra(RecognizerIntent.EXTRA语言模型,RecognizerIntent.LANGUAGE模型自由形式);
intent.putExtra(RecognizerIntent.EXTRA调用包“voice.recognition.test”);
intent.putExtra(识别器intent.EXTRA_MAX_结果,5);
高级督察(意向);
Log.i(“111111”、“11111111”);
add.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//高级取消();
意向myIntent=新意向(ExpenseAppActivity.this,
加上(类别),;
ExpenseAppActivity.this.startActivity(我的意图);
}
});
view.setOnClickListener(新的view.OnClickListener(){
公共void onClick(视图v){
意向myIntent=新意向(ExpenseAppActivity.this,
ViewDetails.class);
ExpenseAppActivity.this.startActivity(我的意图);
}
});
其他.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
意向myIntent=新意向(ExpenseAppActivity.this,
其他(类别),;
ExpenseAppActivity.this.startActivity(我的意图);
}
});
}
public void onStart()
{
super.onStart();
d(标记“在onStart()事件中”);
}
/*恢复时公开作废()
{
super.onResume();
d(标记“在onResume()事件中”);
}*/
公共void onStop()
{
super.onStop();
Log.d(标记“在onStop()事件中”tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt;
sr.stopListening();
sr.destroy();
}
公共无效暂停()
{
super.onPause();
Log.d(标记“在onPause()事件中TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT;
sr.stopListening();
sr.destroy();
}
公共void onRestart()
{
super.onRestart();
d(标记“在onRestart()事件中”);
sr=SpeechRecognizer.createSpeechRecognizer(此);
sr.setRecognitionListener(新的listener());
意向意向=新意向(识别意向、行动、识别言语);
intent.putExtra(RecognizerIntent.EXTRA语言模型,RecognizerIntent.LANGUAGE模型自由形式);
intent.putExtra(RecognizerIntent.EXTRA调用包“voice.recognition.test”);
intent.putExtra(识别器intent.EXTRA_MAX_结果,5);
高级督察(意向);
Log.i(“111111”、“11111111”);
}
公共空间
{
super.ondestory();
d(标记“在onDestroy()事件中”);
}
类侦听器实现识别侦听器
{
ReadyForSpeech上的公共void(Bundle参数)
{
Log.d(标签“onReadyForSpeech”);
//mText5.setText(“hi”);
}
开始时的公共无效fSpeech()
{
Log.d(标签“onbeginingofspeech”);
//mText2.setText(“1”);
}
在RMSCHANGED上的公共无效(浮动rmsdB)
{
Log.d(标签“onRmsChanged”);
//mText3.setText(“2”);
}
已接收公共无效onBufferReceived(字节[]缓冲区)
{
Log.d(标记“onBufferReceived”);
//mText4.setText(“3”);
}
公共空间一号