캡처 가능한 사운드 웨이브
개요
캡처 가능한 사운드 웨이브는 스트리밍 사운드 웨이브에서 파생되었습니다. 마이크와 같은 입력 장치에서 오디오 데이터를 캡처하고 재생하는 것을 지원하며, 가져온 사운드 웨이브와 동일한 기능(되감기, SoundCues에서의 사용 등)을 갖습니다. 심지어 제약 없이 오디오를 동시에 캡처하고 재생할 수도 있습니다.
음성 활동 감지(Voice Activity Detection, VAD)에 대해서는 이 페이지를 참조하세요.
캡처 가능한 사운드 웨이브는 캡처가 시작되면 iOS와 Android에서 자동으로 마이크 권한을 요청합니다.
기본 사용법
캡처 가능한 사운드 웨이브 생성하기
먼저 캡처 가능한 사운드 웨이브를 생성해야 합니다.
- Blueprint
- C++
UCapturableSoundWave* CapturableSoundWave = UCapturableSoundWave::CreateCapturableSoundWave();
조기 파괴를 방지하기 위해 캡처 가능한 사운드 웨이브를 강한 참조로 취급해야 합니다 (예: Blueprints에서 별도의 변수에 할당하거나 C++에서 UPROPERTY()
사용).
사용 가능한 입력 장치 가져오기
이 기능을 사용하려면 먼저 캡처에 사용할 수 있는 모든 오디오 입력 장치를 가져와야 합니다.
- Blueprint
- C++
UCapturableSoundWave::GetAvailableAudioInputDevices(FOnGetAvailableAudioInputDevicesResultNative::CreateWeakLambda(this, [](const TArray<FRuntimeAudioInputDeviceInfo>& AvailableDevices)
{
// Handle the result
}));
캡처 시작 및 중지
사용 가능한 장치를 얻은 후에는 입력 장치에서 오디오 데이터 캡처를 시작하고 필요할 때 중지할 수 있습니다.
- Blueprint
- C++
// Assuming CapturableSoundWave is a UE reference to a UCapturableSoundWave object (or its derived type)
// Start capturing audio data from the input device with the specified device ID (0 in this case)
CapturableSoundWave->StartCapture(0);
// Stop capturing audio data
CapturableSoundWave->StopCapture();
DeviceId는 이전 단계에서 얻은 사용 가능한 장치 배열 내의 장치 인덱스입니다. 기본 오디오 입력 장치를 사용하려면 Blueprints에서는 -1
을, C++에서는 Audio::DefaultDeviceIndex
(이는 INDEX_NONE
과 동일함)를 전달하세요. 때로는 0번 인덱스가 기본 장치가 아닐 수 있기 때문입니다.
캡처 상태 확인
사운드 웨이브가 현재 오디오를 캡처 중인지 확인할 수 있습니다:
- Blueprint
- C++
// Assuming CapturableSoundWave is a reference to a UCapturableSoundWave object
bool bIsCapturing = CapturableSoundWave->IsCapturing();
고급 기능
음성 캡처 음소거 및 해제
캡처 프로세스를 중단하지 않고 오디오 데이터의 누적을 방지하기 위해 음성 캡처를 음소거하거나 해제할 수 있습니다.
- Blueprint
- C++
// Assuming CapturableSoundWave is a UE reference to a UCapturableSoundWave object (or its derived type)
CapturableSoundWave->ToggleMute(true);
UE 5.3 이상: 캡처 시작 및 중단 시 더 이상 끊김이 발생하지 않으므로, ToggleMute
는 StartCapture
/StopCapture
와 동일한 효과를 냅니다. 성능 최적화를 위해 ToggleMute
를 전혀 사용하지 않아도 될 수 있습니다.
UE 5.2 및 이전 버전: StartCapture
를 통한 캡처 시작 시 경미한 끊김이 발생할 수 있습니다. 이러한 버전에서는 캡처를 자주 켜고 끌 때 ToggleMute
사용을 권장합니다. 덜 중요한 시점(예: 로딩 화면)에 캡처 자체를 먼저 시작한 다음, 음성 데이터가 실제로 누적되는 시점을 제어하기 위해 음소거/음소거 해제를 사용해야 합니다.
UE 5.2 또는 이전 버전을 사용 중이고 약간의 멈춤 현상을 제거하려면, 이 멈춤이 무시될 수 있는 시점에 캡처를 시작하는 것을 고려하세요. 예를 들어, 게임의 로딩 화면 중에 캡처를 시작하고, 그 직후 캡처 가능 사운드 웨이브를 음소거한 다음, 음성 데이터를 캡처할 필요가 있을 때 끊김 없이 캡처 가능 사운드 웨이브의 음소거를 해제할 수 있습니다.
완전한 예제
캡처 가능 사운드 웨이브 사용의 완전한 구현 예제는 다음과 같습니다:
- Blueprint
- C++
이것은 캡처 가능 사운드 웨이브를 사용하여 입력 장치(마이크)로부터 음성 데이터를 캡처하는 기본적인 코드 예제입니다.
이 예제는 EXAMPLEMODULE
모듈 내 UCaptureAudioClassExample
클래스에 위치한 CaptureAudioExample
함수를 사용합니다.
예제를 성공적으로 실행하려면, .Build.cs 파일의 PublicDependencyModuleNames
또는 PrivateDependencyModuleNames
에 RuntimeAudioImporter
모듈을 추가하고, 프로젝트의 .uproject 파일에도 추가해야 합니다.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Object.h"
#include "CaptureAudioClassExample.generated.h"
UCLASS(BlueprintType)
class EXAMPLEMODULE_API UCaptureAudioClassExample : public UObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void CaptureAudioExample();
private:
// Please pay attention to making the StreamingSoundWave a hard reference, such as using UPROPERTY(), to prevent it from being prematurely garbage collected
UPROPERTY()
class UCapturableSoundWave* CapturableSoundWave;
};
#include "CaptureAudioClassExample.h"
#include "Sound/StreamingSoundWave.h"
#include "AudioCaptureDeviceInterface.h"
void UCaptureAudioClassExample::CaptureAudioExample()
{
// Create a capturable sound wave
CapturableSoundWave = UCapturableSoundWave::CreateCapturableSoundWave();
// Capture audio data from the default input device
CapturableSoundWave->StartCapture(Audio::DefaultDeviceIndex);
// Delay for 5 seconds, just for demonstration purposes
FTimerHandle TimerHandle;
GetWorld()->GetTimerManager().SetTimer(TimerHandle, [this]()
{
// Stop capturing audio data
CapturableSoundWave->StopCapture();
// Play the sound wave
UGameplayStatics::PlaySound2D(GetWorld(), CapturableSoundWave);
}, 5, false);
}