Skip to content

Commit

Permalink
Working on UI and UX
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshg committed May 15, 2017
1 parent 5d5bae6 commit 5591dc4
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 131 deletions.
5 changes: 2 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
github "Alamofire/Alamofire" "4.4.0"
github "Clipy/Magnet" "v2.0.0"
github "OAuthSwift/OAuthSwift" "1.1.1"
github "Clipy/Magnet" "v2.0.1"
github "Octree/SwiftyWave" "0.0.2"
github "SwiftyJSON/SwiftyJSON" "3.1.4"
github "apple/swift-protobuf" "0.9.901"
github "audiokit/AudioKit" "v3.6"
github "grpc/grpc-swift" "b570094bd0ac26b3b41d062f1f219c6119d058a3"
github "grpc/grpc-swift" "a8a2c1892b80f961dc2225befccfd1da329a0d4b"
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions MacAssistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
FF17DA081EB56CCC003E1412 /* google.assistant.embedded.v1alpha1.client.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF17DA061EB56CCC003E1412 /* google.assistant.embedded.v1alpha1.client.pb.swift */; };
FF17DA0A1EB56CD4003E1412 /* embedded_assistant.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF17DA091EB56CD4003E1412 /* embedded_assistant.pb.swift */; };
FF17DA0C1EB56CDB003E1412 /* status.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF17DA0B1EB56CDB003E1412 /* status.pb.swift */; };
FF2652021EC93DEE00ACDBB5 /* begin_prompt.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = FF2652011EC93DEE00ACDBB5 /* begin_prompt.mp3 */; };
FF41AB811EB40FB8003E994B /* Magnet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FF41AB801EB40FB8003E994B /* Magnet.framework */; };
FF41AB821EB40FB8003E994B /* Magnet.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FF41AB801EB40FB8003E994B /* Magnet.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
FF41AB841EB40FC6003E994B /* Magnet.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = FF41AB831EB40FC6003E994B /* Magnet.framework.dSYM */; };
Expand Down Expand Up @@ -41,6 +42,7 @@
FFA471071EB2D47300A5F89A /* SpeechWaveformView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFA471061EB2D47300A5F89A /* SpeechWaveformView.swift */; };
FFA471091EB2DF8D00A5F89A /* AudioKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FFA471081EB2DF8D00A5F89A /* AudioKit.framework */; };
FFA4710A1EB2DF8D00A5F89A /* AudioKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FFA471081EB2DF8D00A5F89A /* AudioKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
FFCED5F81EC4268B0049676B /* WaveformView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFCED5F71EC4268B0049676B /* WaveformView.swift */; };
FFE68A761EB2A81E00F60EF5 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFE68A751EB2A81E00F60EF5 /* LoginViewController.swift */; };
FFE68A781EB2A81E00F60EF5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FFE68A771EB2A81E00F60EF5 /* Assets.xcassets */; };
FFE9B12F1EC110FC0034E85B /* roots.pem in Resources */ = {isa = PBXBuildFile; fileRef = FFE9B12E1EC110FC0034E85B /* roots.pem */; };
Expand Down Expand Up @@ -93,6 +95,7 @@
FF17DA061EB56CCC003E1412 /* google.assistant.embedded.v1alpha1.client.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = google.assistant.embedded.v1alpha1.client.pb.swift; sourceTree = "<group>"; };
FF17DA091EB56CD4003E1412 /* embedded_assistant.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = embedded_assistant.pb.swift; sourceTree = "<group>"; };
FF17DA0B1EB56CDB003E1412 /* status.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = status.pb.swift; sourceTree = "<group>"; };
FF2652011EC93DEE00ACDBB5 /* begin_prompt.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = begin_prompt.mp3; sourceTree = "<group>"; };
FF41AB801EB40FB8003E994B /* Magnet.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Magnet.framework; path = Carthage/Build/Mac/Magnet.framework; sourceTree = "<group>"; };
FF41AB831EB40FC6003E994B /* Magnet.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = Magnet.framework.dSYM; path = Carthage/Build/Mac/Magnet.framework.dSYM; sourceTree = "<group>"; };
FF41AB851EB416F4003E994B /* API.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = "<group>"; };
Expand All @@ -115,6 +118,7 @@
FFA471041EB2CE4500A5F89A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = MacAssistant/Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
FFA471061EB2D47300A5F89A /* SpeechWaveformView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeechWaveformView.swift; sourceTree = "<group>"; };
FFA471081EB2DF8D00A5F89A /* AudioKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioKit.framework; path = Carthage/Build/Mac/AudioKit.framework; sourceTree = "<group>"; };
FFCED5F71EC4268B0049676B /* WaveformView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WaveformView.swift; sourceTree = "<group>"; };
FFE68A701EB2A81E00F60EF5 /* MacAssistant.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MacAssistant.app; sourceTree = BUILT_PRODUCTS_DIR; };
FFE68A731EB2A81E00F60EF5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
FFE68A751EB2A81E00F60EF5 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -211,13 +215,15 @@
FFE68A751EB2A81E00F60EF5 /* LoginViewController.swift */,
FFA471011EB2C9F200A5F89A /* LoginView.xib */,
FFA471061EB2D47300A5F89A /* SpeechWaveformView.swift */,
FFCED5F71EC4268B0049676B /* WaveformView.swift */,
FFA471031EB2CE4500A5F89A /* MainMenu.xib */,
FF6AA52E1EBA77F60009E342 /* Authenticator.swift */,
FF6AA5341EBA8A980009E342 /* Constants.swift */,
FFF3FABC1EBD545D005E87C9 /* ConversationEntry.swift */,
FFE9B1321EC189D60034E85B /* CustomPlot.swift */,
FFE9B12E1EC110FC0034E85B /* roots.pem */,
FFE9B1341EC195AB0034E85B /* google_oauth.json */,
FF2652011EC93DEE00ACDBB5 /* begin_prompt.mp3 */,
FFE68A7C1EB2A81E00F60EF5 /* Info.plist */,
FFE68A771EB2A81E00F60EF5 /* Assets.xcassets */,
);
Expand Down Expand Up @@ -289,6 +295,7 @@
FFE9B12F1EC110FC0034E85B /* roots.pem in Resources */,
FFA471001EB2C9EB00A5F89A /* AssistantView.xib in Resources */,
FFE68A781EB2A81E00F60EF5 /* Assets.xcassets in Resources */,
FF2652021EC93DEE00ACDBB5 /* begin_prompt.mp3 in Resources */,
FFF3FAC11EBD5ADD005E87C9 /* LoadingView.xib in Resources */,
FFA471021EB2C9F200A5F89A /* LoginView.xib in Resources */,
FFA471051EB2CE4500A5F89A /* MainMenu.xib in Resources */,
Expand All @@ -304,6 +311,7 @@
files = (
FFA470CD1EB2B9B900A5F89A /* AppDelegate.swift in Sources */,
FF17DA0A1EB56CD4003E1412 /* embedded_assistant.pb.swift in Sources */,
FFCED5F81EC4268B0049676B /* WaveformView.swift in Sources */,
FFA471071EB2D47300A5F89A /* SpeechWaveformView.swift in Sources */,
FFF3FABD1EBD545E005E87C9 /* ConversationEntry.swift in Sources */,
FF41AB861EB416F4003E994B /* API.swift in Sources */,
Expand Down
20 changes: 13 additions & 7 deletions MacAssistant/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ class API {
self.converseState = nil
do { self.converseState = try ConverseState(serializedData: response.result.conversationState) }
catch { print("ConverseState parse error") }
self.delegate.updateRequestText(response.result.spokenRequestText)
self.delegate.updateResponseText(response.result.spokenResponseText.isEmpty ? "Speaking response..." : response.result.spokenResponseText)
// TODO: Save file before playing it?
if response.audioOut.audioData.count > 0 {
buf.append(response.audioOut.audioData)
if !response.result.spokenRequestText.isEmpty {
self.delegate.updateRequestText(response.result.spokenRequestText)
}
self.delegate.updateResponseText(response.result.spokenResponseText.isEmpty ? "Speaking response..." : response.result.spokenResponseText)
if response.audioOut.audioData.count > 0 { buf.append(response.audioOut.audioData) }
if response.eventType == .endOfUtterance { self.delegate.stopListening() }
}
if let error = error { print("Initial receive error: \(error)") }
}

func initiateRequest() {
func initiateRequest(volumePercent: Int32) {
var request = ConverseRequest()
request.config = ConverseConfig()

Expand All @@ -69,7 +68,7 @@ class API {
var audioOutConfig = AudioOutConfig()
audioOutConfig.sampleRateHertz = Int32(Constants.GOOGLE_SAMPLE_RATE) // TODO: Play back the response and find the appropriate value
audioOutConfig.encoding = .mp3
audioOutConfig.volumePercentage = 50
audioOutConfig.volumePercentage = volumePercent
request.config.audioOutConfig = audioOutConfig

do {
Expand All @@ -92,6 +91,7 @@ class API {
func doneSpeaking() {
do {
try currentCall?.closeSend { print("Closed send") }
// Receive all response audio responses
DispatchQueue.global().async {
while true {
do {
Expand All @@ -113,6 +113,12 @@ class API {
}
}

func donePlayingResponse() {
if followUp {
delegate.startListening()
}
}

func debugPrint(result: ConverseReponse) {
print("\n++++++++++++++++++++++++++++++")
print("Close receive result error: \(result.error.code)")
Expand Down
16 changes: 11 additions & 5 deletions MacAssistant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
super.init()
popover.contentViewController = NSViewController(nibName: "LoadingView", bundle: nil)
// popover.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
registerHotkey()
// registerHotkey() // TODO: Proper interaction between hotkey and window
}

func applicationWillFinishLaunching(_ notification: Notification) {
Expand Down Expand Up @@ -65,14 +65,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
keyCombo: keyCombo,
target: self,
action: #selector(AppDelegate.hotkeyPressed))
hotKey.register()
hotKey.register()
}

func hotkeyPressed(sender: AnyObject?) {
if (!popover.isShown) {
if !popover.isShown {
showPopover(sender: sender)
} else if let controller = popover.contentViewController as? AssistantViewController {
if controller.isListening {
controller.stopListening()
}
}

if (isLoggedIn) {
(popover.contentViewController as? AssistantViewController)?.startListening()
}
Expand All @@ -84,12 +87,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func showPopover(sender: AnyObject?) {
if let button = statusItem.button {
popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
}
}

func closePopover(sender: AnyObject?) {
popover.performClose(sender)
if let controller = popover.contentViewController as? AssistantViewController {
controller.stopListening()
}
}

func togglePopover(sender: AnyObject?) {
Expand Down
Loading

0 comments on commit 5591dc4

Please sign in to comment.