Skip to main content
Version: 1.4.x

AIPlayer Set up

Full setup process (4 steps)
  • Step 1: Add AIPlayer's parent layout to the page you want to use.
  • Step 2: Prepare App ID, authentication key(User Key) that will be used in the Authenticate function.
  • Step 3: Get the AI to use by implementing the Authenticate response.
  • Step 4: Initialize AIPlayer to the desired AI.

You can create AIPlayer and get the View(UserControl) object through the GetObject() function.

// practical use example
private AIPlayer _aiPlayer; // AIPlayer object to be used in cs
public AIPlayerView AIPlayerObject // View (UserControl) of AIPlayer to be used in xaml
{
get => _aiPlayer.GetObject();
private set => OnPropertyChanged(nameof(AIPlayerObject));
}

Step 1. Organize your layout

Configure the View to use AI Human in the XAML file. Create a ContentControl to place the AI and bind the AIPlayer. In the CS file, the property of the actual binding object is defined.

public AIPlayerView AIPlayerObject
{
get => _aiPlayer.GetObject();
private set => OnPropertyChanged(nameof(AIPlayerObject));
}
...
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<ContentControl Margin="0" Grid.Column="0" Content="{Binding Path=AIPlayerObject}" />
</Grid>
...

The Authenticate function requires 2 parameters. These two are App ID and User Key information.

UserKey is a unique string generated by DeepBrain AI and should never be disclosed. If you call the API using this authentication key, you will receive available Default AI data and a token to be used in the future.

If token refresh is required because the token expired, it can be refreshed by calling Authenticate() again.

Step 3. Implement Authenticate and Get the AI list

If you have all the necessary Authenticate function parameters mentioned in step 2, you are ready for authentication. Input these parameters inti Authenticate AIHuam.AIAPI.Instance and implement a callback function. If authentication is successful, AI list will be returned. If you do not have permission to any of the AIs, aiList returns null.

public ObservableCollection<AIAPI.AI> AIs { get; private set; }

...

AIAPI.Instance.Authenticate(APPID, USERKEY, (aiList, error) => {
string message = string.Empty;
if (error == null)
{
message = string.Format("Auth Complete, Avaliable Count : {0}", aiList.ai.Length);

/* e.g.)
"ai":[{"aiName":"vida","aiDisplayName":"Vida","language":"en"},
{"aiName":"bret","aiDisplayName":"Bret","language":"en"},
{"aiName":"danny","aiDisplayName":"Danny","language":"en"},
{"aiName":"kang","aiDisplayName":"Kang","language":"ko"}]
*/

AIs = new ObservableCollection<AIAPI.AI>();
foreach (AIAPI.AI item in aiList.ai)
{
AIs.Add(item);
}
}
else
{
message = string.Format("Auth Error : {0}", error.ToString());
}

AIHuman.Util.Log.LogWrite(message);
});

Step 4. Initialize AIPlayer to the desired AI

After authenticating and checking the list of available AIs, it is necessary to initialize the AI first in order to actually use a specific AI. To initialize it, create AIPlayer with the desired AIName as shown below. If there is an existing AIPlayer, delete it and create a new one.

Once you initialize, AIPlayer downloads necessary resources based on initial settings and becomes active. You can also receive AI status through callback function registered in the second argument of the AIPlayer constructor.

public AIPlayer AIPlayerObject // View Binding object
{
...
}

...

private AIAPI.AI _selectedAI;
public AIAPI.AI SelectedAI
{
get => _selectedAI;
set
{
if (value == null)
{
return;
}

_selectedAI = value;
OnPropertyChanged(nameof(SelectedAI));
UpdateSelectedAI();
}
}

...

private void UpdateSelectedAI()
{
if (_aiPlayer != null)
{
_aiPlayer.Dispose();
_aiPlayer = null;
}

GestureList?.Clear();
SpeakableLanguages?.Clear();

_aiPlayer = new(SelectedAI.aiName, this);
AIPlayerObject = _aiPlayer.GetObject();

...
}