Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The Orbita Voice SDK will enable the integration of Orbita Voice services across iOS apps. Development of services such as audio processing, speech to text conversion from scratch can be time-consuming. For this reason, Orbita has developed the SDK that can integrate all the voice-related services that a business requires, for easy and quick implementation.

Table of Contents

Prerequisites

- iOS 10.0 or above

- Xcode 9.0 or above

Orbita Voice SDK Installation

Note

Contact Orbita Support to access these files

  • iOS-SDK.zip files

  • iOS-SDK-sample.zip files

Creating a new project in Xcode

1. Open Xcode.

2. Select “Project” from the File menu – File - New

...

6. A new project will be created with the “Product name” that was given in the previous step.

...

Import the SDK files to the project

1. Unzip the SDK.zip file.

...

5. Select the folder named “SDK” which is added to Xcode and click on “Add”

...

Pod Installation

1. Go to Terminal and change the directory to project directory

...

7. Close the project in Xcode and open ‘<Project name>.xcworkspace’ file from the project directory

...

Build procedure

1. Go to Product – Run from the file menu. The build would run into errors in google STT. Please follow the below link to resolve it.

...

3. Replace the Google API key in SpeechRecognitionService.swift

Using the SDK

Login to Orbita services

Code Block
let servicePayload = [“username":"","password":""]
WebServices.sharedManager.LoginRequest(servicePayload as NSDictionary, success:
{ (response, requestName, status) in
})
{ (error, requestName,status) in
}

...

Code Block
{
"_id": "58e72a68343f94a80803e3ba",
"roles": [
"admin"
],
"firstName": "Alpesh",
"lastName": "Patel",
"avatarSrc": "img/avatar0.jpg",
"attributes": {
"oauthSettings": {
"alexa": {
"userId": "M2G739YPXVIGU8",
"access": {
"expiresAt": "2018-05-15T18:36:55+05:30",
"tokenSecret": "Your_Token_Secret",
"token": "Your_Token"
}
}
},
"email": "alpesh@bebaio.com",
"title": "CTO",
"pinSecurityExpired": "2018-05-03T12:07:46.586Z"
},
"token": "",
"personaType": "592e9e508c0f67381784b15a",
"personaProfile": {
"username": "alpesh@bebaio.com",
"firstName": "Alpesh",
"lastName": "Patel",
"securityPin": "2548",
"securityPinInterval": "1",
"timezone": "America/Chicago"
},
"iat": 1526480494,
"exp": 1526494894
}

Using SpeechAudioProcessor Class for Audio Processing

Code Block
Assign SpeechAudioProcessor.shared.delegate = self

Start the recognition task

We need to request authorization from the user to use a microphone for voice recognition.

...

text = recognized text from speech recognizer.

Post Utterance to Orbita Voice server

Code Block
let requestToken = UserDefaults.standard.value(forKey: "orbitaRequestToken") as! String
let serviceDict = ["utterance":UtteranceString,"sessionId":sessionID,"orbitaToken":requestToken]
WebServices.sharedManager.PostVoiceRecognitionService(params:serviceDict as NSDictionary, success:
{ (response, requestName, status) in
})
{ (error, requestName, status) in
}

...

Code Block
{
"orbitaPayload": {
"payload": {
"multiagent": {
"voice": {
"sayText": "<p>Hello World! <break strength=\"none\" time=\"5s\"/> How can I help?</p><p> </p> <p>hello how are you</p><p> </p>",
"rePrompt": "<p>how can i help?<audio src=\"https://s3.amazonaws.com/orbitahealth/clients/sandbox5/assets/editor/audio/SampleAudio_0.4mbd7504e20-5ec6-11e8-91c4-cf90c900530e.mp3\"/></p>"
},
"chat": {
"chatText": "<p>Hello World! How can I help?</p>",
"rePrompt": "<p>how can I help you?</p>"
},
"screen": {
"shortTitle": "Hi",
"longTitle": "Hi there",
"body": "<p>Hello World! How can I help?</p>",
"smallImage": "",
"largeImage": ""
},
"buttons": {
"type": "",
"name": "buttons",
"choices": []
}
}
},
"type": "4",
"name": "orbita"
},
"text": "Hello World! How can I help? hello how are you ",
"reprompt": "Hello World! How can I help? hello how are you ",
"sessionEnd": false,
"replaceWord": {
"two": [
"to",
"too"
],
"six": [
"sex"
],
"ten": [
"tan",
"tin"
]
},
“sayTextAudio”:[],
“audioContent”:[],
”repromptAudio”:[]
}

Play Audio Content

To play the audio content from Orbita voice service

Code Block
var audioContent = [String:Any]()
audioContent = serviceResponse.value(forKey: "sayTextAudio") as! [String:Any]
var data = NSData()
if(audioContent["data"] is [String]){
let dataArray = audioContent["data"] as! [String]
data = NSData(base64Encoded: dataArray[0], options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)!
}
SpeechAudioProcessor.shared.PlayAudio(data: data as Data)

...

Code Block
SpeechAudioProcessor.shared.StopAudio()

To synthesize the text from Orbita voice service to speech (TTS)

Code Block
var audioText = serviceResponse.value(forKey: "text") as! String
SpeechAudioProcessor.shared.SpeakText(string: audioText)

...