0

コマンドを言ってアプリに実行させることができるアプリをプログラムしようとしています。しかし、ここに問題があります。GoogleVoice がポップアップする RecognizerIntent を使用したくありません。自分だけのカスタムをしたい。誰かが私にそれを可能にする助けやヒントを教えてもらえますか? そして、私が何かを言ってタスクを実行した後に結果を使用する方法についての助けはありますか?

更新されたコード:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class VoicingMain extends Activity implements OnClickListener {

ListView lv;    
private SpeechRecognizer sr;
private Intent srIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.voicing);
    lv = (ListView) findViewById(R.id.lvList);
    Button b = (Button) findViewById(R.id.bStartVoicing);
    b.setOnClickListener(this);
    boolean available = SpeechRecognizer.isRecognitionAvailable(this);
    Log.d("Speech", "available = " + available);
    sr = SpeechRecognizer.createSpeechRecognizer(this);
    sr.setRecognitionListener(new SpeechListener());

}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    srIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    srIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    srIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            this.getPackageName());
    srIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    Log.d("speech", "button active");
    sr.startListening(srIntent);
    new CountDownTimer(3000, 1000) {

        @Override
        public void onTick(long arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFinish() {
            // TODO Auto-generated method stub
            sr.stopListening();
        }

    }.start();
}

private class SpeechListener implements RecognitionListener {

    @Override
    public void onBeginningOfSpeech() {
        // TODO Auto-generated method stub
        Log.d("Speech", "onBeginningOfSpeech");
    }

    @Override
    public void onBufferReceived(byte[] arg0) {
        // TODO Auto-generated method stub
        Log.d("Speech", "onBufferReceived");
    }

    @Override
    public void onEndOfSpeech() {
        // TODO Auto-generated method stub
        Log.d("Speech", "onEndOfSpeech");
    }

    @Override
    public void onError(int arg0) {
        // TODO Auto-generated method stub
        Log.d("Speech", "onError");
    }

    @Override
    public void onEvent(int arg0, Bundle arg1) {
        // TODO Auto-generated method stub
        Log.d("Speech", "onEvent");
    }

    @Override
    public void onPartialResults(Bundle arg0) {
        // TODO Auto-generated method stub
        Log.d("Speech", "onPartialResults");
    }

    @Override
    public void onReadyForSpeech(Bundle arg0) {
        // TODO Auto-generated method stub
        Log.d("Speech", "onReadyForSpeech");
    }

    @Override
    public void onResults(Bundle arg0) {
        // TODO Auto-generated method stub
        Log.d("Speech", "results");
    }

    @Override
    public void onRmsChanged(float arg0) {
        // TODO Auto-generated method stub
        // Log.d("Speech", "onRmsChanged");
    }

}

}

これは私がこれまでに持っているものです

4

2 に答える 2