Virtual Avatar
  • iOS : Objective-C
  • Android
  • Overview
  • Client SDKs
  • Demo app
  • Getting started
    • Integrate the SDK
    • Create a virtual avatar
    • ZegoCharacterHelper instructions
  • Guides
  • Best practice
  • Error codes
  • Server APIs
  • Documentation
  • Virtual Avatar
  • Guides
  • Talking avatar

Talking avatar

Last updated:2023-03-14 17:18

Introduction

ZEGOCLOUD's Virtual Avatar now supports the Talking Avatar feature, it supports real-time driving of the virtual avatar's facial movements and corresponding audio playback of text-to-speech by inputting text.

Prerequisites

Before accessing the Text-Driven feature, please ensure that:

  • We have contacted ZEGO business personnel to enable text drive related permissions.

Implementation

1 Get module source code

After downloading Avatar SDK, find and copy the apiservice folder according to SDK's root directory /helper/apiservice and paste it to your app code to get the source code of talking avatar.

Since the ZegoTextAPI depends on the Virtual Avatar SDK, the app project must include Avatar SDK.

2 (Optional) Import dependencies

In the source code, ZegoTextAPI uses the AFNetworking network library and YYKit components, while you are allowed to import or modify the network implementation as needed based on the actual situation.

To import dependencies without modifying the network library or components, run the following:

pod 'AFNetworking', '~> 4.0'
pod 'YYKit'

3 Authentication

Before using the ZegoTextAPI, go to ZEGOCLOUD Admin Console to get your project's AppID and AppSign.

The AppID and AppSign filled in here must be the same as the information that was used to apply for authentication when creating the avatar.

#import "ZegoTextLicenseCustomer.h"

[ZegoTextLicenseCustomer setZegoTextAppID:0];
[ZegoTextLicenseCustomer setZegoTextAppSign:@""];

4 Method calls

After building a basic avatar:

  1. Initialize the ZegoTextAPI object and pass it in the Character object (can get from CharacterHelper).
// Initialize ZegoTextAPI,
ZegoTextAPI *textAPI = [[ZegoTextAPI alloc] initWithCharacter:self.helper.getCharacter];

//Set proxy
textAPI.delegate = self;
  1. Call the playTextExpression method, type your text, and the avatar will make the corresponding expressions and say what you type.
// Type the text that needs to be converted into emotions
[textAPI playTextExpression:@"The text to be played"];
  • The maximum length of the text is 1000 characters/time. For extra-long texts, you may have to call this method multiple times to play in order.
  • You are allowed to adjust the audio playback logic in the source code according to the actual situation.
  1. To stop driving the avatar to talk via text, call the stopTextExpression method.
//Stop the talking avatar.
[textAPI stopTextExpression];

5 Callbacks

After setting the proxy, ZegoTextAPI will call back the corresponding method.

// Callback when the talking avatar function starts.
- (void)onStart;

// Callback when an error occurs. For the Error Codes, refer to [Common Error Codes- Text Driver Error Codes]( <a href="https://docs.zegocloud.com/article/14596</a> )
- (void)onError:(ZegoTextAPIErrorCode)errorCode message:(NSString *_Nullable)message;

// Callback when the talking avatar function ends.
- (void)onEnd;

For related error codes, refer to Error codes- Talking Avatar.

Page Directory