# 初始化语音客户端对象

> How to initialize the Vivox voice client object.

必须先创建并初始化语音客户端，然后才能执行其他 Vivox SDK 操作。在语音客户端初始化过程中，Vivox SDK 会设置并启动其所有不同的子系统。这可能会导致加载其他共享库，使开发者可以在连接到 Vivox 服务之前自定义各种 Vivox SDK 选项。例如，开发者可以在可用编解码器、音频互切设置与日志记录级别之间进行选择。

[`await VivoxService.Instance.InitializeAsync(VivoxConfigurationOptions config)`](https://docs.unity3d.com/Packages/com.unity.services.vivox@latest/index.html?subfolder=/api/Unity.Services.Vivox.IVivoxService.html#Unity_Services_Vivox_IVivoxService_InitializeAsync_Unity_Services_Vivox_VivoxConfigurationOptions_) 具有可以用于选择 Vivox Core SDK 配置的可选参数。

以下代码示例说明如何在 Windows、macOS、Android 和 iOS 上创建和初始化语音客户端：

```cs
using System;
using UnityEngine;
using Unity.Services.Authentication;
using Unity.Services.Core;
using Unity.Services.Vivox;

async void Start()
{
    await UnityServices.InitializeAsync();
    await AuthenticationService.Instance.SignInAnonymouslyAsync();

    await VivoxService.Instance.InitializeAsync();
}
```

\*\*重要信息：\*\*如果客户端已初始化，而应用程序尝试再次初始化客户端，则它会遇到 `5041:VxErrorAlreadyInitialized` 错误。如需了解此错误，请参阅 [Vivox SDK 错误代码](/vivox-unity/developer-guide/troubleshooting/error-codes.md)。

如需了解有关 Unity Authentication 服务的更多详细信息，请参阅[使用 Authenticaiton 包进行登录](./sign-in-with-authentication-package.md)。如需了解其他身份验证方法，请参阅[使用自定义 ID 登录](../../unity/developer-guide/vivox-unity-sdk-basics/sign-in-with-custom-id)，或者如果您已在应用程序中使用 Vivox 访问令牌，请参阅 [VAT 与 UAS 结合使用](../implement-vivox-unity/integrate-existing-vat-project-with-uas)。
