Ver código fonte

<优化tts播报流程,增加log日志>

weizhengliang 4 anos atrás
pai
commit
04e2e116eb

+ 3 - 0
app/src/main/java/com/wdkl/callingmainnurse/common/Constants.java

@@ -341,4 +341,7 @@ public class Constants {
      * 是否是免提状态  add by waderson 20190802
      */
     public static boolean HANDS_FREE = true;
+
+    //是否打开debug
+    public static boolean DEBUG = false;
 }

+ 26 - 0
app/src/main/java/com/wdkl/callingmainnurse/ui/activity/OtherSettingsActivity.java

@@ -80,6 +80,13 @@ public class OtherSettingsActivity extends BaseActivity {
     @Bind(R.id.activity_tv_transfer_timeout)
     TextView tvTimeout;
 
+    @Bind(R.id.group_device_debug)
+    RadioGroup groupDebug;
+    @Bind(R.id.rb_set_debug_on)
+    RadioButton rbDebugOn;
+    @Bind(R.id.rb_set_debug_off)
+    RadioButton rbDebugOff;
+
     private List<HostDevice> hostDeviceList = new ArrayList<>();
     private String selectHostDeviceId;
 
@@ -203,6 +210,25 @@ public class OtherSettingsActivity extends BaseActivity {
                 }
             }
         });
+
+        if (Constants.DEBUG) {
+            rbDebugOn.setChecked(true);
+        } else {
+            rbDebugOff.setChecked(true);
+        }
+        groupDebug.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(RadioGroup group, int checkedId) {
+                switch (checkedId) {
+                    case R.id.rb_set_debug_on:
+                        Constants.DEBUG = true;
+                        break;
+                    case R.id.rb_set_debug_off:
+                        Constants.DEBUG = false;
+                        break;
+                }
+            }
+        });
     }
 
     @Override

+ 9 - 1
app/src/main/java/com/wdkl/callingmainnurse/ui/fragment/CallingBedFragment.java

@@ -1504,7 +1504,9 @@ public class CallingBedFragment extends BaseFragment implements SicknessBedAdapt
                     case "call_4"://增援呼叫护士主机
                     case "call_6": //门口机呼叫护士主机
                         if (isMySelfMachine(nurseHostID)) {//只有属于自己管的机器才能加进列表
-                            LogUtil.d("speech", "enableTTS: " + enableTTS());
+                            if (Constants.DEBUG) {
+                                LogUtil.d("speech", "enableTTS: " + enableTTS() + ", call state: " + Constants.CALL_STATE);
+                            }
                             if (enableTTS()) {
                                 //使用TTS播报
                                 if (Constants.CALL_STATE.equals(Constants.STANDBY)) {
@@ -1876,6 +1878,9 @@ public class CallingBedFragment extends BaseFragment implements SicknessBedAdapt
     //语音播报
     private void startSpeak(UdpEntity entity) {
         String speechText = getSpeechText(entity);
+        if (Constants.DEBUG) {
+            LogUtil.d(TAG, "startSpeak: " + speechText);
+        }
         if (!TextUtils.isEmpty(speechText)) {
             loopingUdpentity = entity;
             showUrgentWindow(entity);
@@ -1897,6 +1902,9 @@ public class CallingBedFragment extends BaseFragment implements SicknessBedAdapt
         String type = entity.getType();
         String rnb = entity.getRoomNumber();
         String bnb = entity.getBedNumber();
+        if (Constants.DEBUG) {
+            Log.d(TAG, "getSpeechText==> tag: " + tag + ", type: " + type + ", room no: " + rnb + ", bed no: " + bnb);
+        }
         String text = "";
         switch (type) {
             case DOOR_CALL: //门口机

+ 27 - 23
app/src/main/java/com/wdkl/callingmainnurse/util/SpeechUtil.java

@@ -23,7 +23,6 @@ public class SpeechUtil {
     public volatile static ArrayList<String> speechTextList = new ArrayList<>();
     private Thread speechThread;
     private boolean isSpeechLoop = true;
-    private Context context;
     private String speakSpeech;
     private final Object lockObject = new Object();
 
@@ -39,7 +38,6 @@ public class SpeechUtil {
     }
 
     public void init(Context context) {
-        this.context = context;
         textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
             @Override
             public void onInit(int status) {
@@ -64,7 +62,9 @@ public class SpeechUtil {
 
     public void newSpeech(String text, boolean emergency) {
         synchronized (lockObject) {
-            LogUtil.d(TAG, "add text speech: " + text);
+            if (Constants.DEBUG) {
+                LogUtil.d(TAG, "add text speech: " + text);
+            }
             if (emergency) {
                 speechTextList.add(0, text);
             } else {
@@ -75,7 +75,9 @@ public class SpeechUtil {
     }
 
     public synchronized void speak(final String text) {
-        LogUtil.d(TAG, "start speak");
+        if (Constants.DEBUG) {
+            LogUtil.d(TAG, "tts speak: " + text);
+        }
         isStop = false;
         textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, "uniqueId");
         textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@@ -107,12 +109,12 @@ public class SpeechUtil {
     }
 
     public void stopSpeak() {
-        synchronized (lockObject) {
-            if (textToSpeech.isSpeaking()) {
-                textToSpeech.stop();
-                speechTextList.clear();
-                isStop = true;
-                speakIndex = 0;
+        if (textToSpeech.isSpeaking()) {
+            textToSpeech.stop();
+            speechTextList.clear();
+            isStop = true;
+            speakIndex = 0;
+            if (Constants.DEBUG) {
                 LogUtil.d(TAG, "stop speak");
             }
         }
@@ -121,7 +123,9 @@ public class SpeechUtil {
     public void removeSpeak(String text) {
         synchronized (lockObject) {
             if (!TextUtils.isEmpty(text) && !TextUtils.isEmpty(speakSpeech)) {
-                LogUtil.d(TAG, "remove speak: " + text);
+                if (Constants.DEBUG) {
+                    LogUtil.d(TAG, "remove speak: " + text);
+                }
                 if (text.equals(speakSpeech) && textToSpeech.isSpeaking()) {
                     textToSpeech.stop();
                     speechTextList.remove(text);
@@ -139,15 +143,13 @@ public class SpeechUtil {
     }
 
     public void release() {
-        synchronized (lockObject) {
-            speechTextList.clear();
-            isStop = true;
-            speakIndex = 0;
-            if (textToSpeech != null) {
-                textToSpeech.stop();
-                textToSpeech.shutdown();
-                textToSpeech = null;
-            }
+        speechTextList.clear();
+        isStop = true;
+        speakIndex = 0;
+        if (textToSpeech != null) {
+            textToSpeech.stop();
+            textToSpeech.shutdown();
+            textToSpeech = null;
         }
     }
 
@@ -163,17 +165,19 @@ public class SpeechUtil {
     public class SpeechRunnable implements Runnable {
         public void run() {
             while (isSpeechLoop) {
-                synchronized (lockObject) {
+                //synchronized (lockObject) {
                     if (speechTextList.size() > 0 && isStop) {
                         speakSpeech = speechTextList.get(0);
-                        LogUtil.d(TAG, "speakSpeech: " + speakSpeech);
+                        if (Constants.DEBUG) {
+                            LogUtil.d(TAG, "speakSpeech: " + speakSpeech);
+                        }
                         speak(speakSpeech);
 
                         //if (speechTextList.contains(speakSpeech)) {
                             speechTextList.remove(speakSpeech);
                         //}
                     }
-                }
+                //}
 
                 try {
                     Thread.sleep(50);

+ 38 - 0
app/src/main/res/layout/activity_other_settings_layout.xml

@@ -177,4 +177,42 @@
             android:layout_marginLeft="20dp"/>
     </LinearLayout>
 
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="80dp"
+        android:padding="20dp"
+        android:gravity="center_vertical">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="打开调试:"
+            android:textColor="@color/white"
+            android:textSize="28sp"/>
+
+        <RadioGroup
+            android:id="@+id/group_device_debug"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="30dp"
+            android:orientation="horizontal">
+            <RadioButton
+                android:id="@+id/rb_set_debug_on"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="是"
+                android:textColor="@color/white"
+                android:textSize="28sp"/>
+            <RadioButton
+                android:id="@+id/rb_set_debug_off"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="60dp"
+                android:text="否"
+                android:textColor="@color/white"
+                android:textSize="28sp"/>
+        </RadioGroup>
+    </LinearLayout>
+
+
 </LinearLayout>