Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilingual ios demo #558

Merged
merged 15 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ node_modules
demo/respeaker-rpi0/picovoice_demo_mic
__pycache__
build
demo/c/cmake-build-debug
demo/c/cmake-build-debug

*.ppn
*.rhn
*.pv
14 changes: 7 additions & 7 deletions demo/flutter-clock/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
14 changes: 7 additions & 7 deletions demo/flutter/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
59 changes: 35 additions & 24 deletions demo/ios-swiftui/BaristaDemo/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import SwiftUI

struct ContentView: View {

let activeBlue = Color(red: 55/255, green: 125/255, blue: 1, opacity: 1)
let inactiveGrey = Color(red: 0.6, green: 0.6, blue: 0.6)



@ObservedObject var viewModel = ViewModel()

var body: some View {

return
VStack(alignment: .center, spacing:20) {
VStack(alignment: .center, spacing: 20) {
Text("Say 'Hey Barista!'").font(.largeTitle).foregroundColor(activeBlue)
Image("cuppa").resizable().scaledToFit().padding(.horizontal,50.0)
Image("cuppa").resizable().scaledToFit().padding(.horizontal, 50.0)

VStack(alignment: .center, spacing: 5) {

Text("Beverage Size").font(.body).fontWeight(.semibold).foregroundColor(inactiveGrey)

// Size row
HStack(alignment: .center, spacing: 10) {
ForEach(viewModel.sizeSel) { item in
Button(action: {}){
Button {
Text(item.title)
.font(.system(size: 20))
.foregroundColor(item.isSelected ? Color.white : inactiveGrey)
.padding(10)

}
.disabled(true)
.background(
Expand All @@ -40,17 +39,22 @@ struct ContentView: View {
)
}
}

// # Shot row
Text("Espresso Shots").font(.body).fontWeight(.semibold).foregroundColor(inactiveGrey).padding(.top, 8.0)
Text("Espresso Shots")
.font(.body)
.fontWeight(.semibold)
.foregroundColor(inactiveGrey)
.padding(.top, 8.0)

HStack(alignment: .center, spacing: 7) {
ForEach(viewModel.shotSel) { item in
Button(action: {}){
Button {
Text(item.title)
.font(.system(size: 16))
.foregroundColor(item.isSelected ? Color.white : inactiveGrey)
.padding(8.0)

}
.disabled(true)
.background(
Expand All @@ -63,46 +67,53 @@ struct ContentView: View {
)
}
}

// Beverage row
Text("Beverage Type").font(.body).fontWeight(.semibold).foregroundColor(inactiveGrey).padding(.top, 8.0)
Text("Beverage Type")
.font(.body)
.fontWeight(.semibold)
.foregroundColor(inactiveGrey)
.padding(.top, 8.0)

VStack(alignment: .center, spacing: 6) {
HStack(alignment: .center) {
ForEach(0..<viewModel.bevSel.count/2) { i in
Button(action: {}){
Button {
Text(viewModel.bevSel[i].title)
.font(.system(size: 15))
.foregroundColor(viewModel.bevSel[i].isSelected ? Color.white : inactiveGrey)
.padding(8.0)

}
.disabled(true)
.background(
Capsule()
.fill(viewModel.bevSel[i].isSelected ? activeBlue : Color.white)
.overlay(
Capsule()
.stroke(inactiveGrey, lineWidth: 2).opacity(viewModel.bevSel[i].isSelected ? 0 : 1)
.stroke(inactiveGrey, lineWidth: 2)
.opacity(viewModel.bevSel[i].isSelected ? 0 : 1)
)
)
}
}
HStack(alignment: .center) {
ForEach(viewModel.bevSel.count/2..<viewModel.bevSel.count) { i in
Button(action: {}){
Button {
Text(viewModel.bevSel[i].title)
.font(.system(size: 15))
.foregroundColor(viewModel.bevSel[i].isSelected ? Color.white : inactiveGrey)
.padding(8.0)

}
.disabled(true)
.background(
Capsule()
.fill(viewModel.bevSel[i].isSelected ? activeBlue : Color.white)
.overlay(
Capsule()
.stroke(inactiveGrey, lineWidth: 2).opacity(viewModel.bevSel[i].isSelected ? 0 : 1)
.stroke(inactiveGrey, lineWidth: 2)
.opacity(viewModel.bevSel[i].isSelected ? 0 : 1)
)
)
}
Expand All @@ -128,7 +139,7 @@ struct ContentView: View {
.foregroundColor(activeBlue)
.opacity(viewModel.missedCommand ? 1 : 0)
}.padding(.top, 10.0)

}.padding(.vertical, 6.0)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity).background(Color.white)
}
Expand Down
73 changes: 43 additions & 30 deletions demo/ios-swiftui/BaristaDemo/ViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
import SwiftUI
import Picovoice

struct CapsuleSelection: Codable, Identifiable{
var title:String
var id:String
var isSelected:Bool
init(title:String) {
struct CapsuleSelection: Codable, Identifiable {
var title: String
var id: String
var isSelected: Bool

init(title: String) {
self.title = title
self.id = title.lowercased()
self.isSelected = false
}
}

class ViewModel: ObservableObject {

@Published var sizeSel = [CapsuleSelection(title: "Small"), CapsuleSelection(title: "Medium"), CapsuleSelection(title: "Large")]
@Published var shotSel = [CapsuleSelection(title: "Single Shot"), CapsuleSelection(title: "Double Shot"), CapsuleSelection(title: "Triple Shot")]
@Published var bevSel = [CapsuleSelection(title: "Americano"), CapsuleSelection(title: "Cappuccino"), CapsuleSelection(title: "Coffee"),
CapsuleSelection(title: "Espresso"),CapsuleSelection(title: "Latte"),CapsuleSelection(title: "Mocha")]


@Published var sizeSel = [
CapsuleSelection(title: "Small"),
CapsuleSelection(title: "Medium"),
CapsuleSelection(title: "Large")
]
@Published var shotSel = [
CapsuleSelection(title: "Single Shot"),
CapsuleSelection(title: "Double Shot"),
CapsuleSelection(title: "Triple Shot")
]
@Published var bevSel = [
CapsuleSelection(title: "Americano"),
CapsuleSelection(title: "Cappuccino"),
CapsuleSelection(title: "Coffee"),
CapsuleSelection(title: "Espresso"),
CapsuleSelection(title: "Latte"),
CapsuleSelection(title: "Mocha")
]

@Published var isListening = false
@Published var missedCommand = false
@Published var errorMessage = ""

let ACCESS_KEY = "{YOUR_ACCESS_KEY_HERE}"

let contextPath = Bundle.main.path(forResource: "coffee_maker_ios", ofType: "rhn")
let keywordPath = Bundle.main.path(forResource: "hey barista_ios", ofType: "ppn")
var picovoiceManager:PicovoiceManager!
var picovoiceManager: PicovoiceManager!

init() {
do {
picovoiceManager = PicovoiceManager(
accessKey : ACCESS_KEY,
accessKey: ACCESS_KEY,
keywordPath: keywordPath!,
onWakeWordDetection: {
DispatchQueue.main.async {
Expand All @@ -47,29 +61,28 @@ class ViewModel: ObservableObject {
DispatchQueue.main.async {
if inference.isUnderstood {
if inference.intent == "orderBeverage" {
if let size = inference.slots["size"]{
if let size = inference.slots["size"] {
if let i = self.sizeSel.firstIndex(where: { $0.id == size }) {
self.sizeSel[i].isSelected = true
}
}
if let numberOfShots = inference.slots["numberOfShots"]{

if let numberOfShots = inference.slots["numberOfShots"] {
if let i = self.shotSel.firstIndex(where: { $0.id == numberOfShots }) {
self.shotSel[i].isSelected = true
}
}
if let beverage = inference.slots["beverage"]{

if let beverage = inference.slots["beverage"] {
if let i = self.bevSel.firstIndex(where: { $0.id == beverage }) {
self.bevSel[i].isSelected = true
}
}
}
}
else {
} else {
self.missedCommand = true
}

self.isListening = false
}
})
Expand All @@ -83,25 +96,25 @@ class ViewModel: ObservableObject {
errorMessage = "ACCESS_KEY activation refused"
} catch is PicovoiceActivationLimitError {
errorMessage = "ACCESS_KEY reached its limit"
} catch is PicovoiceActivationThrottledError {
} catch is PicovoiceActivationThrottledError {
errorMessage = "ACCESS_KEY is throttled"
} catch {
errorMessage = "\(error)"
}
}

func clearSelectedItems() {
for i in sizeSel.indices {
sizeSel[i].isSelected = false
}

for i in shotSel.indices {
shotSel[i].isSelected = false
}

for i in bevSel.indices {
bevSel[i].isSelected = false
}
}

}
Loading