From 2a7361afa8f240e16eb2800bd5252c5364c4d0e8 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Sun, 18 Jul 2021 16:13:07 -0400 Subject: [PATCH] Send the text heard on the TCP connection. --- ListenerApp/ContentView.swift | 27 ++++++++++++++++++++++++++- ListenerApp/Info.plist | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ListenerApp/ContentView.swift b/ListenerApp/ContentView.swift index 1459297..f771e42 100644 --- a/ListenerApp/ContentView.swift +++ b/ListenerApp/ContentView.swift @@ -141,8 +141,33 @@ struct ContentView: View { } private func send(latestText : String) { + guard let client = client else { return } + var commonChars = self.textHeard.count + while (commonChars > 0) { + if (latestText.prefix(commonChars) == self.textHeard.prefix(commonChars)) { + break + } + commonChars -= 1 + } + var stringToSend = "" + if (commonChars < self.textHeard.count) { + stringToSend = String(repeating: "\u{8}", count: self.textHeard.count - commonChars) + } + stringToSend.append(contentsOf: latestText.suffix(latestText.count - commonChars)) - self.textHeard = latestText + if (stringToSend.count > 0) { + // TODO - Handle strings to send that are longer than 64K (doubt that would happen though) + // TODO - Try to convert encoding from utf8 to something the GS can understand. + switch (client.send(data: pack("CFBundleShortVersionString 1.0 CFBundleVersion - 61 + 66 LSRequiresIPhoneOS NSSpeechRecognitionUsageDescription