C# 스크립트에서 오디오 탭 사용
How to add Audio Taps through C# scripts.
읽는 시간 1분최근 업데이트: 19일 전
이 섹션에서는 에디터 UI가 아닌 스크립트를 통해 오디오 탭을 추가하는 방법을 설명합니다.
Capture Source Tap 및 Channel Audio Tap
C# 스크립트를 통해 씬에 Capture Source Tap과 Channel Audio Tap을 추가할 수 있습니다. 다음은 스크립트를 통해 Vivox Channel Audio Tap 오디오에 에코 효과를 추가하는 방법의 예입니다.빈 게임 오브젝트를 생성한 다음 모든 오디오에 에코가 적용되도록private GameObject _channelAudioGameObject;public void AddChannelAudioEffect(){ // Create the GameObject _channelAudioGameObject = new GameObject("ChannelAudioGameObject"); // Add the Tap to it _channelAudioGameObject.AddComponent<VivoxChannelAudioTap>(); // Also add an echo filter, for example _channelAudioGameObject.AddComponent<AudioEchoFilter>();}
VivoxChannelAudioTapAudioEchoFilterVivoxCaptureSourceTapParticipant Tap 스크립트
Participant Tap은 VivoxParticipant의 클래스CreateVivoxParticipantTapVivoxService.Instance.ParticipantAddedToChannelCreateVivoxParticipantTapParticipantAddedToChannel위의 예제 스크립트는 생성된 오브젝트를 삭제하지 않습니다. 필요한 경우 특정 채널 멤버에 대한 탭만 생성하는 로직을 추가할 수 있습니다.using Unity.Services.Vivox;using UnityEngine;public class ParticipantHandler : MonoBehaviour{ void Start() { VivoxService.Instance.ParticipantAddedToChannel += AddParticipantEffect; } void AddParticipantEffect(VivoxParticipant participant) { var gameObject = participant.CreateVivoxParticipantTap("MyNewGameObject"); gameObject.AddComponent<AudioEchoFilter>(); }}
CreateVivoxParticipantTapVivoxParticipant.DestroyVivoxParticipantTap오디오 탭 상태 모니터링
오디오 탭에는 생성된 오디오 탭의 상태를 모니터링하기 위해 노출된 파라미터 TapId가 있습니다. 탭을 생성한 후 TapId의 값은 0보다 크거나 같아야 합니다. 이는 오류가 없음을 의미합니다. 다음은 탭을 생성하고 TapId에 예상 값이 있는지 확인하는 예입니다.TapId가 0보다 작은 경우 해당 값은 오류를 해결하는 데 도움이 될 수 있습니다. 가능한 값과 오류 발생 이유는 다음과 같습니다.private GameObject _channelAudioGameObject;public void AddChannelAudioEffect(){ // Create the GameObject _channelAudioGameObject = new GameObject("ChannelAudioGameObject"); // Add the Tap to it var tap = _channelAudioGameObject.AddComponent<VivoxChannelAudioTap>(); if (tap.TapId < 0) { Destroy(_channelAudioGameObject); // Destroy the GameObject, since the status is not valid Debug.LogError($"Failed to create VivoxChannelAudioTap"); return; } else { Debug.Log("There was no error creating VivoxChannelAudioTap"); }}
- -1 : 탭이 현재 등록되지 않았습니다. 탭이 인스턴스화되었지만 아직 Vivox에 등록되지 않은 경우 이와 같은 문제가 발생할 수 있습니다. 예를 들어 채널이 자동으로 획득되기를 기다리고 있기 때문입니다.
- -1010 : 탭이 등록되지 않았습니다.
- -1011 : 탭에서 잘못된 참가자 이름으로 등록을 시도했습니다.
- -1012 : 탭에서 잘못된 채널 이름으로 등록을 시도했습니다.
- -1050 : Vivox Participant Tap에만 적용됩니다. 제공된 참가자 이름에서 참가자 URI를 찾을 수 없습니다.
- -1051 : 탭에서 Vivox에 등록을 시도했지만 VivoxService가 초기화되지 않았습니다. 오디오 탭을 초기화하기 전에 VivoxService를 초기화해야 합니다.
- -1052 : 탭에서 잘못된 채널 이름으로 Vivox에 등록을 시도했습니다. 채널 이름을 올바르게 설정해야 합니다.