comparison src/com/five_ten_sg/connectbot/monitor/MonitorService.java @ 4:46a9cdf018a1

allow async tts
author Carl Byington <carl@five-ten-sg.com>
date Mon, 23 Jun 2014 17:09:52 -0700
parents 2be5bca648ab
children d1f095e4f8f0
comparison
equal deleted inserted replaced
3:2be5bca648ab 4:46a9cdf018a1
169 } catch (IOException e) { 169 } catch (IOException e) {
170 Log.e(TAG, "exception in CommunicationThread() constructor, cannot get socket streams", e); 170 Log.e(TAG, "exception in CommunicationThread() constructor, cannot get socket streams", e);
171 } 171 }
172 } 172 }
173 173
174 public void speak(byte [] msg, boolean flush, boolean synchronous) {
175 if (speech) {
176 String smsg = bytesToString(msg);
177 if (synchronous) {
178 HashMap<String, String> myHashParms = new HashMap();
179 myHashParms.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.format("connection %d", connection));
180 talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, myHashParms);
181 try {
182 String x = talkerQueue.take(); // wait for completion
183 } catch (InterruptedException e) {
184 Log.e(TAG, "exception in cm.speak()", e);
185 }
186 }
187 else {
188 talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null);
189 }
190 }
191 }
192
193 public String bytesToString(byte[] b) {
194 char[] c = new char[b.length];
195 int bp = 0;
196 for(int i = 0; i < c.length; i++) {
197 byte b1 = 0;
198 byte b2 = b[bp++];
199 c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF));
200 }
201 return new String(c);
202 }
203
174 public char[] bytesToChars(byte[] b, int len) { 204 public char[] bytesToChars(byte[] b, int len) {
175 char[] c = new char[len >> 1]; 205 char[] c = new char[len >> 1];
176 int bp = 0; 206 int bp = 0;
177 for(int i = 0; i < c.length; i++) { 207 for(int i = 0; i < c.length; i++) {
178 byte b1 = b[bp++]; 208 byte b1 = b[bp++];
379 arg[4] = (char) (len & 0x0000ffff); 409 arg[4] = (char) (len & 0x0000ffff);
380 cm.clientWrite(MONITOR_CMD_GETFIELD, arg); 410 cm.clientWrite(MONITOR_CMD_GETFIELD, arg);
381 } 411 }
382 } 412 }
383 413
384 public static void teSpeak(int connection, String msg, boolean flush) { 414 public static void teSpeak(int connection, String msg, boolean flush, boolean synchronous) {
385 if (speech) talker.speak(msg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null); 415 CommunicationThread cm = clients.get(connection);
416 if (cm != null) cm.speak(msg, flush, synchronous);
386 } 417 }
387 418
388 public static void teDepress(int connection, int vk_key) { 419 public static void teDepress(int connection, int vk_key) {
389 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 420 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731
390 Log.i(TAG, String.format("teDepress %d, %d", connection, vk_key)); 421 Log.i(TAG, String.format("teDepress %d, %d", connection, vk_key));