# HG changeset patch # User Carl Byington # Date 1403568592 25200 # Node ID 46a9cdf018a1d394c51fdfe85cc971fb968795ee # Parent 2be5bca648ab9551279a34c5b6fe33e885b6acda allow async tts diff -r 2be5bca648ab -r 46a9cdf018a1 src/com/five_ten_sg/connectbot/monitor/MonitorService.java --- a/src/com/five_ten_sg/connectbot/monitor/MonitorService.java Mon Jun 23 17:05:16 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/monitor/MonitorService.java Mon Jun 23 17:09:52 2014 -0700 @@ -171,6 +171,36 @@ } } + public void speak(byte [] msg, boolean flush, boolean synchronous) { + if (speech) { + String smsg = bytesToString(msg); + if (synchronous) { + HashMap myHashParms = new HashMap(); + myHashParms.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.format("connection %d", connection)); + talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, myHashParms); + try { + String x = talkerQueue.take(); // wait for completion + } catch (InterruptedException e) { + Log.e(TAG, "exception in cm.speak()", e); + } + } + else { + talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null); + } + } + } + + public String bytesToString(byte[] b) { + char[] c = new char[b.length]; + int bp = 0; + for(int i = 0; i < c.length; i++) { + byte b1 = 0; + byte b2 = b[bp++]; + c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); + } + return new String(c); + } + public char[] bytesToChars(byte[] b, int len) { char[] c = new char[len >> 1]; int bp = 0; @@ -381,8 +411,9 @@ } } - public static void teSpeak(int connection, String msg, boolean flush) { - if (speech) talker.speak(msg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null); + public static void teSpeak(int connection, String msg, boolean flush, boolean synchronous) { + CommunicationThread cm = clients.get(connection); + if (cm != null) cm.speak(msg, flush, synchronous); } public static void teDepress(int connection, int vk_key) {