인증 및 생성하기
The entire setup process consists of four stages.
- 1.1: Create an AIPlayer
- 1.2: SDK User Authentication. (Invalid userKey returns error through the callback)
- 1.3: Getting a list of available AIs. (returns error if not authenticated)
- 1.4: Initialize AIPlayer with the desired AI and Release
1. Create an AIPlayer object.
Initialize the AIPlayer object using its constructors.
const wrapper = document.getElementById("AIPlayerWrapper");
const AI_PLAYER = new AIPlayer(wrapper);
2. SDK User Authentication
In order to use AIPlayer, users must go through an authentication process to prove that he/she has valid permissions. The first step is to obtain a UserKey. UserKey is a unique string generated by DeepBrain AI and should never be disclosed. Create JWT ClientToken on the server using this key. Calling asynchronous AI_PLAYER.generateToken()
function with the created JWT ClientToken as a parameter returns avaliable AI list and authenticated token information.
The result is delivered as JSON. The result contains JWT token, token expiration date, and available AI model list. When the token expires, you can refresh the token by calling generateToken again. As error returns {succeed: false}.
const result = await AI_PLAYER.generateToken({ appId: appId, token: clientToken });
/* result
{"succeed":true,
"token":"eyJhbGciO...",
"tokenExpire":1608032460152,
"defaultAI": {"ai_na...} */
3. Getting a list of available AIs
Once authentication is complete, AIPlayer holds all authentication results. You can check available AI list information by calling AIPlayer.getAIList()
function. If the authentication key is invalid or there are no available AIs associated with the user account, the function returns {succeed: false}
.
const result = await AI_PLAYER.getAIList();
/* result
{ "succeed":true,
"ai":[{"aiName":"vida","aiDisplayName":"Vida","language":"en"},
{"aiName":"bret","aiDisplayName":"Bret","language":"en"},
{"aiName":"danny","aiDisplayName":"Danny","language":"en"},
{"aiName":"samh","aiDisplayName":"Samh","language":"en"},
{"aiName":"kang","aiDisplayName":"Kang","language":"ko"}]} */
- Check the token after authentication
const token = AI_PLAYER.getter("token"); // verifiedToken
4. Initialize AIPlayer to the desired AI and Release
To apply specific AI to the AIPlayer object, you need to reset its state to hold the desired AI model. Call init(...)
function with AI name, size, position, and authentication token as a parameter to reinitialize AIPlayer object. AIPlayer will load AI resources according to the parameters passed, and it will be ready to perform further action calls. You can also asynchronously fetch list of sample sentences.
- Initializing the AIPlayer
const result = await AI_PLAYER.init({
aiName: "...", zIndex: 0, size: 1.0, left: 0, top: 0, speed: 1.0
});
/* result
{ "texts":[
"Nice to meet you.",
"Are you sleeping? Wake up!",
"Wow. If I were your class, I would choose you.",
"I am not that hungry, but don't you want to have more?",
"Today i am going to tell you an incredible story."
]}*/
- Check the maximum length of sentences that can be synthesized by AI at once.
const maxTextLength = AI_PLAYER.getter("maxTextLength");
- Check which languages AI can speak
const language = AI_PLAYER.getter("language"); // en, kr, zh ...
Release Object
- When you want to terminate or destroy AIPlayer, you must call
release()
to release the resource.
- When you want to terminate or destroy AIPlayer, you must call
AI_PLAYER.release();