Installation

Add Avatars Swift package from git.

https://github.com/avatechgg/avatars-swift.git

How it works

In order to make the Avatar SDK works in ios environment, we have built a simple frontend and wrap it up with WKWebView. All data input from ios app will be sent to the webview and takes effect after handling.

Therefore, please turn on Outgoing Connections (Client), otherwise webview will not work.

The Code

You need to first import the package and create a stateObject with AvatarViewModel(). It contain various data for creating the AvatarView.

import Avatars

struct ContentView: View {
    // Data the frontend needed to create the canvas.
    @StateObject var viewModel = AvatarViewModel(
        // The id of avatar you created
        avatarId: "fb4051f8-5969-480f-b57b-fcfc66c5b6f6",

        // Model position
        x: 0,
        y: 0,

        // Model scale & rotation
        scale: 1,
        rotation: 0,

        // For emotion setting
        currentEmotion: ""
    )
}

Then you can create the AvatarView in body with the stateObject to create the canvas.

var body: some View {
    VStack {
        AvatarView(viewModel) // The canvas showing Avatar
    }
}

Advance settings

Avatars Swift package also support avatar interaction incluing audio lip-sync and emotions.

References

AvatarViewModel

FieldTypeDescription
avatarIdStringThe id of the avatar you created. You can create you own avatar at here!
xFloatThe position of the avatar on the x axis.
yFloatThe position of the avatar on the y axis.
scaleFloatThe scale of the avatar. Default is set to ‘1’.
rotationFloatSet the value between 0 and 1 to rotate the avatar.
currentEmotionStringThe emotion avatar is currently showing. Changing this value to make the avatar express emotion. Emotions the avatar can express is stored at availableEmotion.
availableEmotionString[]An array of string containing all available emotion the avatar can express. Pass one of those string to currentEmotion will change the emotion.
audioSourceStringThe source of the audio, usually an Url. The audio will be played automatically once the value is changed.
rawBase64AudioStringThe source of the audio which is encoded with Base64 format. Usually used with base64EncodedString() to encode the audio data.