Selaa lähdekoodia

兼容点阵屏T4类型控制卡语音模块,增加点阵屏语音播报语速设置

weizhengliang 1 vuosi sitten
vanhempi
commit
4c1a253d9a

+ 25 - 0
android_host/src/main/h10_z3128_1h/java/com/wdkl/ncs/android/component/nursehome/fragment/LedSettingsFragment.kt

@@ -128,6 +128,7 @@ class LedSettingsFragment: Fragment() {
         val ledProgramTime = SettingConfig.getLedProgramTime(baseActivity)
         val ledVoiceVolume = SettingConfig.getLedVoiceVolume(baseActivity)
         val ledVoiceTimes = SettingConfig.getLedVoiceTimes(baseActivity)
+        val ledVoiceSpeed = SettingConfig.getLedVoiceSpeed(baseActivity)
         val ledInfoType = SettingConfig.getLedInfoType(baseActivity)
         val info = SettingConfig.getLedCustomInfo(baseActivity)
 
@@ -143,6 +144,10 @@ class LedSettingsFragment: Fragment() {
         tv_led_voice_times.setText(ledTimes)
         skb_led_voice_times.progress = ledVoiceTimes
 
+        val voiceSpeed = BaseApplication.appContext.getString(R.string.led_voice_speed, ledVoiceSpeed)
+        tv_led_voice_speed.setText(voiceSpeed)
+        skb_led_voice_speed.progress = ledVoiceSpeed
+
         //led_refresh.setRefreshFooter(ClassicsFooter(activity))
 
         if (ledInfoType == 1) {
@@ -279,6 +284,26 @@ class LedSettingsFragment: Fragment() {
             }
         })
 
+        skb_led_voice_speed.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
+            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
+                val times = BaseApplication.appContext.getString(R.string.led_voice_speed, progress)
+                tv_led_voice_speed.setText(times)
+            }
+
+            override fun onStartTrackingTouch(seekBar: SeekBar?) {
+                //
+            }
+
+            override fun onStopTrackingTouch(seekBar: SeekBar?) {
+                if (seekBar!!.progress <= 0) {
+                    val text = BaseApplication.appContext.getString(R.string.less_then, 1)
+                    showMessage(text)
+                    seekBar.progress = 1
+                }
+                SettingConfig.setLedVoiceSpeed(baseActivity, seekBar.progress)
+            }
+        })
+
         val info = SettingConfig.getLedCustomInfo(baseActivity)
         group_led_info_type.setOnCheckedChangeListener { group, checkedId ->
             if (checkedId == R.id.rb_date_time) {

+ 38 - 6
android_host/src/main/h10_z3128_1h/java/com/wdkl/ncs/android/component/nursehome/led/LedC2MManager.java

@@ -134,15 +134,32 @@ public class LedC2MManager extends LedManager {
         int server_port = 9999;
         String text = "";
         byte[] data;
+        int led_type = SettingConfig.getLedType(BaseApplication.appContext);
 
         if (stopVoice) {
-            data = VoiceModel.getStopVoiceData();
+            if (led_type == 0) {
+                //T卡
+                data = VoiceModel.getStopVoiceDataT4();
+            } else {
+                //默认C卡
+                data = VoiceModel.getStopVoiceDataC2M();
+            }
         } else {
             text = voiceText;
             for (int j = 0; j < 2; j++) {
                 text = text + "," + voiceText;
             }
-            data = VoiceModel.getVoiceData(text);
+            int volume = SettingConfig.getLedVoiceVolume(BaseApplication.appContext);
+            int speed = SettingConfig.getLedVoiceSpeed(BaseApplication.appContext);
+            text = "[v" + volume +"]" + "[s" + speed + "]" + text;
+
+            if (led_type == 0) {
+                //T卡
+                data = VoiceModel.getVoiceDataT4(text);
+            } else {
+                //默认C卡
+                data = VoiceModel.getVoiceDataC2M(text);
+            }
         }
 
         DatagramSocket s = null;
@@ -178,18 +195,33 @@ public class LedC2MManager extends LedManager {
         try {
             byte[] data;
             String text = "";
+            int led_type = SettingConfig.getLedType(BaseApplication.appContext);
 
             if (stopVoice) {
-                data = VoiceModel.getStopVoiceData();
+                if (led_type == 0) {
+                    //T卡
+                    data = VoiceModel.getStopVoiceDataT4();
+                } else {
+                    //默认C卡
+                    data = VoiceModel.getStopVoiceDataC2M();
+                }
             } else {
                 text = voiceText;
                 int loop = SettingConfig.getLedVoiceTimes(BaseApplication.appContext) - 1;
                 for (int j = 0; j < loop; j++) {
                     text = text + "," + voiceText;
                 }
-                String volume = Integer.toString(SettingConfig.getLedVoiceVolume(BaseApplication.appContext));
-                text = "[v" + volume +"]" + text;
-                data = VoiceModel.getVoiceData(text);
+                int volume = SettingConfig.getLedVoiceVolume(BaseApplication.appContext);
+                int speed = SettingConfig.getLedVoiceSpeed(BaseApplication.appContext);
+                text = "[v" + volume +"]" + "[s" + speed + "]" + text;
+
+                if (led_type == 0) {
+                    //T卡
+                    data = VoiceModel.getVoiceDataT4(text);
+                } else {
+                    //默认C卡
+                    data = VoiceModel.getVoiceDataC2M(text);
+                }
             }
 
             Socket socket = new Socket(ip, 10000);

+ 19 - 37
android_host/src/main/h10_z3128_1h/java/com/wdkl/ncs/android/component/nursehome/settingconfig/SettingConfig.java

@@ -128,6 +128,7 @@ public class SettingConfig {
     private static final String KEY_SP_LED_PROGRAM_TIME = "KEY_SP_LED_PROGRAM_TIME";
     private static final String KEY_SP_LED_VOICE_VOLUME = "KEY_SP_LED_VOICE_VOLUME";
     private static final String KEY_SP_LED_VOICE_TIMES = "KEY_SP_LED_VOICE_TIMES";
+    private static final String KEY_SP_LED_VOICE_SPEED = "KEY_SP_LED_VOICE_SPEED";
     private static final String KEY_SP_LED_INFO_TYPE = "KEY_SP_LED_INFO_TYPE";
     private static final String KEY_SP_LED_CUSTOM_INFO = "KEY_SP_LED_CUSTOM_INFO";
 
@@ -407,43 +408,6 @@ public class SettingConfig {
         getEditor(context).putInt(KEY_SP_HANDS_FREE_INPUT_VOLUME, value).apply();
     }
 
-
-    /**
-     * 获取主机免提播放音量
-     *
-     * @return
-     */
-    /*public static int getHostHandsFreePlayVolume(Context context) {
-        return getSP(context).getInt(KEY_SP_HOST_HANDS_FREE_PLAY_VOLUME, host_hands_free_play_volume);
-    }*/
-
-    /**
-     * 设置主机免提播放音量
-     *
-     * @param value
-     */
-    /*public static void setHostHandsFreePlayVolume(Context context, int value) {
-        getEditor(context).putInt(KEY_SP_HOST_HANDS_FREE_PLAY_VOLUME, value).apply();
-    }*/
-
-    /**
-     * 获取主机手柄播放音量
-     *
-     * @return
-     */
-    /*public static int getHostGamepadPlayVolume(Context context) {
-        return getSP(context).getInt(KEY_SP_HOST_GAMEPAD_PLAY_VOLUME, host_gamepad_play_volume);
-    }*/
-
-    /**
-     * 设置主机手柄播放音量
-     *
-     * @param value
-     */
-    /*public static void setHostGamepadPlayVolume(Context context, int value) {
-        getEditor(context).putInt(KEY_SP_HOST_GAMEPAD_PLAY_VOLUME, value).apply();
-    }*/
-
     public static int getHostCallVolume(Context context) {
         return getSP(context).getInt(KEY_SP_HOST_CALL_VOLUME, default_host_call_volume);
     }
@@ -833,6 +797,24 @@ public class SettingConfig {
     }
 
     /**
+     * 获取点阵屏语音播报语速
+     *
+     * @return
+     */
+    public static int getLedVoiceSpeed(Context context) {
+        return getSP(context).getInt(KEY_SP_LED_VOICE_SPEED, 4);
+    }
+
+    /**
+     * 设置点阵屏语音播报语速
+     *
+     * @param value
+     */
+    public static void setLedVoiceSpeed(Context context, int value) {
+        getEditor(context).putInt(KEY_SP_LED_VOICE_SPEED, value).apply();
+    }
+
+    /**
      * 获取点阵屏默认显示类型
      *
      * @return

+ 25 - 0
android_host/src/main/h10_z3128_1h/res/layout/fragment_led_settings.xml

@@ -319,6 +319,31 @@
                 android:thumb="@drawable/seekbar_thumb"/>
         </LinearLayout>
 
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:padding="14dp"
+            android:orientation="vertical">
+            <TextView
+                android:id="@+id/tv_led_voice_speed"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text=""
+                android:textSize="22sp" />
+
+            <SeekBar
+                android:id="@+id/skb_led_voice_speed"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_vertical"
+                android:layout_marginTop="8dp"
+                android:max="10"
+                android:maxHeight="2dp"
+                android:progressDrawable="@drawable/po_seekbar"
+                android:thumb="@drawable/seekbar_thumb"/>
+        </LinearLayout>
+
         <RelativeLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"

+ 92 - 7
listenvision/src/main/java/com/listenvision/model/VoiceModel.java

@@ -8,6 +8,7 @@ import android.text.TextUtils;
 
 public class VoiceModel {
 
+    //C系列控制卡
     //帧头4字节:0x55,0xaa,0x00,0x00
     //地址1字节:0x01  --485通讯屏号,默认1
     //标识1字节:0x01
@@ -18,12 +19,28 @@ public class VoiceModel {
     //帧长度2字节:0x21,0x00
     //语音数据最多512字节:帧头[0xfd],长度[0x00,0x1e],命令字[0x01],文字编码格式[0x00],待合成语音文本[...]
     //帧尾4字节:0x00,0x00,0x0d,0x0a
+    //sample C2M: 55AA0000010111D5000000000000120000001200FD000F01003132333435D3EFD2F4CEC4B1BE00000D0A
 
-    private static byte[] head = {(byte)0x55, (byte)0xaa, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x01, (byte)0x11, (byte)0xd5, (byte)0x00, (byte)0x00,
+    //T系列控制卡:
+    //帧头:55 AA 00 00
+    //地址:01(可配置)
+    //标志:01
+    //操作码:00 D9
+    //保留:00 00
+    //帧序号:00 00 00 00
+    //总长:“数据”字段的长度。(可不给长度,由控制卡自动计算)
+    //帧长:“数据”字段的长度。(同总长,可不给长度,由控制卡自动计算)
+    //数据:有效数据,格式详细参见 下一节“数据字段格式”。
+    //帧尾:00 00 0D 0A
+    //sample T4:  55AA0000010100D90000000000000000000000002474656C6C3A3132333435D3EFD2F4CEC4B1BE00000D0A
+
+    private static final byte[] head_c = {(byte)0x55, (byte)0xaa, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x01, (byte)0x11, (byte)0xd5, (byte)0x00, (byte)0x00,
             (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00};
-    private static byte[] end = {(byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x0a};
+    private static final byte[] head_t = {(byte)0x55, (byte)0xaa, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x01, (byte)0x00, (byte)0xd9, (byte)0x00, (byte)0x00,
+            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00};
+    private static final byte[] end = {(byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x0a};
 
-    public static byte[] getVoiceData(String text) {
+    public static byte[] getVoiceDataC2M(String text) {
         if (!TextUtils.isEmpty(text)) {
             try {
                 //语音文本字节数组
@@ -46,7 +63,7 @@ public class VoiceModel {
                 //总长度
                 int dataLen = len + 24;
                 byte[] data = new byte[dataLen];
-                System.arraycopy(head, 0, data, 0, 14 /*head.length*/);
+                System.arraycopy(head_c, 0, data, 0, 14 /*head.length*/);
                 System.arraycopy(len2, 0, data, 14 /*head.length*/, 4 /*len2.length*/);
                 System.arraycopy(len1, 0, data, 14+4 /*head.length+len2.length*/, 2 /*len1.length*/);
                 System.arraycopy(voiceData, 0, data, 14+4+2 /*head.length+len2.length+len1.length*/, len /*voiceData.length*/);
@@ -61,8 +78,31 @@ public class VoiceModel {
         return null;
     }
 
-    public static byte[] getStopVoiceData() {
-        byte[] data = {(byte)0x55, (byte)0xaa, (byte)0x00, (byte)0x00, //帧头
+    public static byte[] getVoiceDataT4(String text) {
+        if (!TextUtils.isEmpty(text)) {
+            try {
+                text = "$tell:" + text;
+                //语音文本字节数组
+                byte[] textBytes = text.getBytes("GBK");
+                //总长度
+                int len = textBytes.length;
+                int dataLen = len + 24;
+                byte[] data = new byte[dataLen];
+                System.arraycopy(head_t, 0, data, 0, 20 /*head.length*/);
+                System.arraycopy(textBytes, 0, data, 20 /*head.length*/, len /*voiceData.length*/);
+                System.arraycopy(end, 0, data, 20+len /*head.length+voiceData.length*/, 4 /*end.length*/);
+
+                return data;
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+        return null;
+    }
+
+    public static byte[] getStopVoiceDataC2M() {
+        return new byte[]{(byte)0x55, (byte)0xaa, (byte)0x00, (byte)0x00, //帧头
                 (byte)0x01, //地址
                 (byte)0x01, //标识
                 (byte)0x11, (byte)0xd5, //操作码
@@ -73,7 +113,27 @@ public class VoiceModel {
                 (byte)0xfd, (byte)0x00, (byte)0x01, (byte)0x02, //语音数据区域
                 (byte)0x00, (byte)0x00, (byte)0x0d, (byte)0x0a  //帧尾
         };
-        return data;
+    }
+
+    public static byte[] getStopVoiceDataT4() {
+        try {
+            String text = "$tell:";
+            //语音文本字节数组
+            byte[] textBytes = text.getBytes("GBK");
+            //总长度
+            int len = textBytes.length;
+            int dataLen = len + 24;
+            byte[] data = new byte[dataLen];
+            System.arraycopy(head_t, 0, data, 0, 20 /*head.length*/);
+            System.arraycopy(textBytes, 0, data, 20 /*head.length*/, len /*voiceData.length*/);
+            System.arraycopy(end, 0, data, 20+len /*head.length+voiceData.length*/, 4 /*end.length*/);
+
+            return data;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
     }
 
     //int转字节数组:低字节在前
@@ -118,4 +178,29 @@ public class VoiceModel {
         }
         return sb.toString();
     }
+
+    public static byte[] hexStr2Bytes(String hex) {
+        int len = hex.length();
+        byte[] result;
+        if (len % 2 == 1){
+            //奇数
+            len++;
+            result = new byte[(len/2)];
+            hex="0"+hex;
+        }else {
+            //偶数
+            result = new byte[(len/2)];
+        }
+
+        int j=0;
+        for (int i = 0; i < len; i+=2){
+            result[j]=hexToByte(hex.substring(i,i+2));
+            j++;
+        }
+        return result;
+    }
+
+    public static byte hexToByte(String inHex){
+        return (byte)Integer.parseInt(inHex,16);
+    }
 }

+ 1 - 0
resource/src/main/res/values-es/strings.xml

@@ -116,6 +116,7 @@
     <string name="led_info_duration">Duración de información de llamada de LED: %d</string>
     <string name="led_voice_volume">Volumen de llamada LED: %d</string>
     <string name="led_voice_times">Tiempos de llamada de LED: %d</string>
+    <string name="led_voice_speed">Velocidad de voz LED: %d</string>
     <string name="less_then">No puede ser menor que: %d</string>
     <string name="led_no_font">Sin archivo de fuente</string>
     <string name="led_font_file_size">Tamaño del archivo de fuente: %d</string>

+ 1 - 0
resource/src/main/res/values-ru/strings.xml

@@ -117,6 +117,7 @@
     <string name="led_info_duration">Продолжительность показа информации о звонке: %d</string>
     <string name="led_voice_volume">Громкость звонка: %d</string>
     <string name="led_voice_times">время вызова экрана: %d</string>
+    <string name="led_voice_speed">Скорость передачи голоса светодиодом: %d</string>
     <string name="less_then">Не может быть меньше: %d</string>
     <string name="led_no_font">Нет файла шрифта</string>
     <string name="led_font_file_size">размер файла шрифта: %d</string>

+ 3 - 2
resource/src/main/res/values-zh/strings.xml

@@ -114,8 +114,9 @@
     <string name="led_voice_off">点阵屏语音播报: 关闭</string>
     <string name="led_font_size">点阵屏字体大小: %d</string>
     <string name="led_info_duration">点阵屏呼叫信息显示时长: %d</string>
-    <string name="led_voice_volume">点阵屏语音呼叫音量: %d</string>
-    <string name="led_voice_times">点阵屏语音呼叫次数: %d</string>
+    <string name="led_voice_volume">点阵屏语音播报音量: %d</string>
+    <string name="led_voice_times">点阵屏语音播报次数: %d</string>
+    <string name="led_voice_speed">点阵屏语音播报语速: %d</string>
     <string name="less_then">不能小于: %d</string>
     <string name="led_no_font">字库文件不存在</string>
     <string name="led_font_file_size">字库文件大小: %d</string>

+ 1 - 0
resource/src/main/res/values/strings.xml

@@ -116,6 +116,7 @@
     <string name="led_info_duration">LED call info duration: %d</string>
     <string name="led_voice_volume">LED call volume: %d</string>
     <string name="led_voice_times">LED call times: %d</string>
+    <string name="led_voice_speed">LED voice speed: %d</string>
     <string name="less_then">Cannot be less than: %d</string>
     <string name="led_no_font">No font file</string>
     <string name="led_font_file_size">font file size: %d</string>