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

Select python interpreter in poetry

Redis Cluster Creation Automation

AIML Framework

Configure Vim from scratch

The Amazing Power of Decorators (Python Wonders — Ep 1)

Work with Windows subsystem for Linux (WSL2)

Restyling of alarms and push notifications for clearer communication

How to Deploy React App to Production

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

The Problem of App Store + Play Store Gatekeeping

How to build logging infrastructure with Firebase for iOS app

The Difference Between Designing Apps for iOS and Android

How to Keep your Social Channels Connected — A Complete Guide to Access Tokens