How to embed a voice assistant into an iOS App(Swift and Objective-C)

From this tutorial you’ll learn

  • How to add a voice interface to an iOS app
  • How to write simple voice commands for an iOS app

The following prerequisites needed to get started

Step 1: Create an iOS app with a single view

  1. Open Xcode and select to create a new Xcode project.
  2. Select Single View App.

Step 2: Add the Alan iOS SDK to the project

  1. Open Alan GitHub, go to the Releases page for the Alan iOS SDK: https://github.com/alan-ai/alan-sdk-ios/releases.
  2. From the latest release download the AlanSDK.framework_<x.x.x>.zip file .

Step 3: Specify the Xcode project settings

  1. When the app gets built need we need to make sure the Alan iOS SDK is embedded . On the General tab, scroll down to the Frameworks, Libraries, and Embedded Content section. To the right of AlanSDK.framework, select Embed and Sign.
sh "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/AlanSDK.framework/frameworks-strip.sh"

Step 4: Integrating Alan with Swift

  1. In the app folder, open the ViewController.swift file.
  2. At the top of the file, import the Alan iOS SDK:
import AlanSDK
class ViewController: UINavigationController {
...
/// Alan button
fileprivate var button: AlanButton!
/// Alan text panel
fileprivate var text: AlanText!
...
}
class ViewController: UINavigationController {
...
fileprivate func setupAlan() {
/// Define the project key
let config = AlanConfig(key: "")

/// Init the Alan button
self.button = AlanButton(config: config)

/// Init the Alan text panel
self.text = AlanText(frame: CGRect.zero)

/// Add the button and text panel to the window
self.view.addSubview(self.button)
self.button.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.text)
self.text.translatesAutoresizingMaskIntoConstraints = false

/// Align the button and text panel on the window
let views = ["button" : self.button!, "text" : self.text!]
let verticalButton = NSLayoutConstraint.constraints(withVisualFormat: "V:|-(>=0@299)-[button(64)]-40-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: views)
let verticalText = NSLayoutConstraint.constraints(withVisualFormat: "V:|-(>=0@299)-[text(64)]-40-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: views)
let horizontalButton = NSLayoutConstraint.constraints(withVisualFormat: "H:|-(>=0@299)-[button(64)]-20-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: views)
let horizontalText = NSLayoutConstraint.constraints(withVisualFormat: "H:|-20-[text]-20-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: views)
self.view.addConstraints(verticalButton + verticalText + horizontalButton + horizontalText)
}
...
}
class ViewController: UINavigationController {
...
override func viewDidLoad() {
...
self.setupAlan()
}
...
}

Step 5: Adding voice commands to interact with Alan

intent (`What is your name?`, p => {
p.play(`It's Alan, and yours?`);
});

intent (`How are you doing?`, p => {
p.play(`Good, thank you. What about you?`);
});

What you finally get after going through this tutorial

Here’s what you can do next

--

--

--

Alan is a B2B Voice AI platform for developers to deploy and manage Voice Interfaces for Enterprise Apps.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Decision tree Regression

Latest cool features of Matplotlib

Making Money on the App Store

Why is BI Governance Important?

OpenAPI generator to spring-boot with custom java validations

Simple Ways of Optimizing Your AWS Cost & Workload

Associate Android Developer Certification By Google

Oracle SaaS Extension using VBCS — Maintain text notes at Customer Site Level

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alan AI

Alan AI

Alan is a B2B Voice AI platform for developers to deploy and manage Voice Interfaces for Enterprise Apps.

More from Medium

Prototyping a Video Creator App for Web3

Choosing Crane Cloud for your startup

Build personalized product notifications with conditional content blocks (examples included!)

Logic gates

How many choices should a SaaS platform provide to users?