AIPlayer Set up
- Step 1: Add AIPlayer's parent layout to the page you want to use.
- Step 2: Prepare App ID, authentication key(userKey) 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>
...
Step 2. Prepare authentication-related information
The Authenticate function requires 2 parameters. These two are App ID and userKey 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 AIHuman.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 = $"Auth Complete, Available Count : {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 = $"Auth Error : {error.ToString()}";
}
AIHuman.Utils.Log.Write(message, Log.Level.Info);
});
Step 4. Initialize AIPlayer to the desired AI
After authentication, you can check the list of AIs that can be used and initialize them to the desired AI. First, create the AIPlayerOptions
object with the desired AIAPI.AI.aiName
as shown in the example code below. If you want to remove the AIPlayer
object that you were using before, use the Dispose
function to release the resource.
AIPlayerOptions
Used as a parameter to create AIPlayer
objects. Valid only at initialization, refer to implementations to use properties or functions of AIPlayer
objects at runtime.
AIName
Set the AI you want to initialize.
Assigns the AIList.AI.aiName
value acquired by the AIHuman.Core.AIAPI.Authenticate
or GetAIList
function to this property.
If you assign any value, the AIPlayer may not initialize normally.
AIScale
Set the Scale of the AI at the initialization.
The default is 1.0f
.
AIMargin
Set the Margin of the AI at initialization.
The default is null
.
AISpeed
Set the Speed of the AI at initialization.
The default is 1.0f
.
AIDisconnection
Set the Disconnection of the AI at initialization.
The default is false
.
AICachingStrategy
Set the local Caching Strategy of the AIPlayer at initialization.
The default is AIHuman.Interface.AIPlayerCachingStrategy.V1
.
CacheLimit
Set the Maximum Local Caching Count of the AIPlayer at initialization.
The default is 2000
units. The unit is AIClipSet
.
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();
AIPlayerOptions options = new AIPlayerOptions(SelectedAI.aiName);
//options.AICachingStrategy = AIPlayerCachingStrategy.V2; // for using local caching
//options.CacheLimit = 300; // for using local caching Limit
//options.AIScale = 1.2f; // for AI Human Scale
//options.AISpeed = 1.2f; // for AI Human Speed
//options.AIMargin = AIMargin; // for AI Human Position
//options.AIDisconnection = true; // for AI Human network on/off-line
_aiPlayer = new AIPlayer(options, this);
AIPlayerObject = _aiPlayer.GetObject();
...
}
Depending on the option, the AIPlayer changes to an operable standby (IDLE) state after initialization (download and load resources) is completed. It can also receive a callback as a second parameter in the AIPlayer
constructor.
- You can set various options using AIPlayerOptions objects!
- You can inherit AIHuman.Interface.IAIPlayerCallback and receive a callback for events, etc. through the implemented object!
- The API Reference also specifies this!
Callbacks such as AI events will be covered in the next chapter.