나의 AI Human 만들기
이 장에서는 신속하게 AIHuman(AIPlayer)를 설정하고 기본 AI를 발화시키는 과정을 알아봅니다. AIPlayer를 처음 설정할 때는 네트워크 상태에 따라 수 분 정도의 로딩이 걸릴 수 있습니다. 이 로딩 과정은 진행율을 모니터링 할 수 있습니다.
테스트를 할 프로젝트를 만들고 이전 단계를 참고하여 프로젝트 설정을 완료합니다.
2. AIPlayer가 포함될 Activity를 생성
여기서는 AILiveQuickStart
라는 Activity를 만들었습니다.
3. 레이아웃 파일 생성
Activity의 contentView
(layout 파일)에 AIPlayer(View의 확장 클래스)가 추가될 parentView
(예, RelativeLayout)를 하나 만들어줍니다.
AI는 parentView에 세로 기준으로 꽉차게 그려집니다.(스케일 1.0)
아래 샘플에서는 viewBinding
을 사용하여 aiWrapper
라는 이름을 붙여 binding.aiWrapper
로 parentView를 얻었습니다. 그러나 viewBinding을 쓰지 않아도 상관없습니다(findViewById()로 사용해도 됨).
- Activity Code
import android.os.Bundle;
import androidx.annotation.Nullable;
public class AILiveQuickStart extends AppCompatActivity {
private IAIPlayer aiPlayer;
private AILiveQuickStartBinding binding; //using viewBinding
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = AILiveQuickStartBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
}
}
- Layout(ailive_quick_start.xml) file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<RelativeLayout
android:id="@+id/aiWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/input_lay" />
...
</RelativeLayout>
4. SDK 인증하기
SDK 사이트에서 Android sample 및 SDK를 다운로드 받아 참조할수 있습니다.
SDK Website에서 프로젝트를 생성하고, 플랫폼은 Android 값을 선택, appId를 입력하고 생성버튼을 클릭 > 다시 들어가보면 userkey가 발급되어 있습니다.

발급된 userkey를 아래 API 입력하고 실행하면, JSON 포맷으로 결과가 옵니다. 성공시에는 default AI같은 정보가 오고 실패하면 aiError가 옵니다.
AIModelInfoManager.generateToken(this, appId, userkey, (aiError, resp) -> {
/* resp{
"succeed":true,
"defaultAI": {"ai_name":...}
*/
});
//or
AIModelInfoManager.generateToken(this, userkey, (aiError, resp) -> {
/* resp{
"succeed":true,
"defaultAI": {"ai_name":...}
*/
});
5. AIPlayer를 생성
AIPlayer는 위에서 만들어준 aiWrapper뷰를 인자로 하여 다음과 같이 만듭니다.
//put aiWrapper in the argument and create AIPlayer.
aiPlayer = AIPlayerFactory.create(AILiveQuickStart.this, binding.aiWrapper, AILIVE, null);