Voice Assistant SDK IOS
Overview
The Voice Assistant SDK provides an easy-to-use features for integrating Voice Assistant capabilities into your IOS applications. With this SDK, you can initialize voice data, play voice messages, and handle playback callbacks effortlessly.
Build up
- Initialization: Load TTS voice configurations from a remote source.
- Voice URL: A URL that contains the voices from remote data source
- Play Voice: Play voice messages with customizable delegate for play, stop, and error events.
- Stop Voice: Stop the playback whenever required.
AmaniVoiceAssistant integration with SPM
You can easily add AmaniVoiceAssistantSDK to your project as Swift Package Manager.
In Xcode project, File > Add Package Dependencies > paste it to search bar under the link.
source "https://github.com/AMANI-AI-ORG/AmaniVoiceAssistantSDK"
AmaniVoiceAsistant SDK Initialization
- Getting from config
import AmaniSDK
#if canImport(AmaniVoiceAssistantSDK)
import AmaniVoiceAssistantSDK
#endif
class ViewController: UIViewController {
var voiceAsistant: AmaniVoiceAssistant?
var config: AppConfig?
override func viewWillAppear() {
super.viewWillAppear()
Task { @MainActor in
do {
try await initAmaniVoiceAssistant()
} catch(let err) {
debugPrint(err)
}
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
#if canImport(AmaniVoiceAssistantSDK)
Task { @MainActor in
do {
//MARK: You must need call stop func where did you set to a property AmaniVoiceAssistant Class.
try? await AmaniUI.sharedInstance.voiceAssistant?.stop()
}catch(let err) {
debugPrint(err)
}
}
#endif
}
func initAmaniVoiceAssistant() async {
self.config = try Amani.sharedInstance.appConfig().getApplicationConfig()
if let ttsURL = self.config?.generalconfigs.ttsVoice {
do {
self.voiceAssistant = try await AmaniVoiceAssistant.init(url: ttsURL)
self.voiceAsistant?.setDelegate(delegate: self)
}catch(let err) {
debugPrint(err)
}
}
}
func playAmaniVoiceAssistant() async {
#if canImport(AmaniVoiceAssistantSDK)
if let docID = self.docID {
Task { @MainActor in
do {
//It should be set according to the key value defined in the JSON file.
try? await AmaniUI.sharedInstance.voiceAssistant?.play(key: "VOICE_\(docID)")
}catch(let error) {
debugPrint("\(error)")
}
}
}
#endif
}
}
//MARK: Set AmaniVoiceAssistant SDK delegate
extension ViewController: AmaniVADelegate {
func onPlay(with text: String) {
//The voice has been started
debugPrint(text)
}
func onStop(with text: String) {
//The voice has been stopped
debugPrint(text)
}
}