1

我正在尝试创建一个 android 应用程序来查找带有文本到语音的手机移动方向。这有很多问题。即,它工作了一些,我没有得到准确的移动。这是我的代码

    @Override
public void onSensorChanged(SensorEvent event) {
    Sensor sensor = event.sensor;
     float [] values = event.values;
     synchronized (this) {
             Log.d(tag, "onSensorChanged: " + sensor + ", x: " + 
                             values[0] + ", y: " + values[1] + ", z: " + values[2]);
     if (sensor.getType() == Sensor.TYPE_ACCELEROMETER ) {
         x.setText("x"+ values[0]);
         y.setText("y"+ values[1]);
         z.setText("z"+ values[2]);

         xa=(int)values[0];// this part of code is only test to see int x and y on Activity
         ya=(int)values[1];

         ball.scrollBy(xa, ya);
         a=Integer.toString(xa);
         b=Integer.toString(ya);
         ball.scrollBy(xa, ya);
         xat.setText(a);
         yat.setText(b);

        if (trigL || trigD || trigR || trigU ) {

             int ttt = TextToSpeech.QUEUE_FLUSH;

            final long ACCEL_SENSOR_DELAY = 100; 
            long lastAccelSensorChange = 0;
            long now = System.currentTimeMillis();
            if ((now-ACCEL_SENSOR_DELAY) > lastAccelSensorChange) {
                lastAccelSensorChange = now;
              ttt = TextToSpeech.QUEUE_FLUSH;
               sensore.registerListener(MainActivity.this, accelerometer,
             trigL = false;
                 trigR = false;
                 trigU = false;
                 trigD = false;

        }
            }

         if (values[0] < -6) {
             trigL = true;
            if(tts.isSpeaking())
            {    
                 return;
            }
            else

            tts.speak("Move Left", TextToSpeech.QUEUE_FLUSH, null);

            values[0]=0;
            values[1]=0;
            return;

        } else if (values[0] > 6) {
            trigR = true;
            if(tts.isSpeaking())
            {
                 return;    
            }
            else
            tts.speak("Move Right", TextToSpeech.QUEUE_FLUSH, null);
            values[0]=0;
            values[1]=0;

            return;
        } 

        else  if (values[1] < -6) {

            trigD = true;
            if(tts.isSpeaking())
            {
                 return;
            }
            else

            tts.speak("Move Down", TextToSpeech.QUEUE_FLUSH, null);
            values[1]=0;
            values[0]=0;

            return;
        } else if (values[1] > 6) {

            trigU = true;
            if(tts.isSpeaking())
            {

                 return;

            }
            else        
            tts.speak("Move Up", TextToSpeech.QUEUE_FLUSH, null);
            values[1]=0;
            values[0]=0;

            return;
        }
     }
     }

}

我正在寻找最后两周。任何建议都可以为我提供充分的帮助。

4

0 回答 0