캡처 가능한 사운드 웨이브
개요
캡처 가능한 사운드 웨이브는 스트리밍 사운드 웨이브에서 파생되었습니다. 마이크와 같은 입력 장치에서 오디오 데이터를 캡처하고 재생할 수 있으며, 임포트된 사운드 웨이브와 동일한 기능(되감기, SoundCue에서의 사용 등)을 지원합니다. 심지어 오디오를 동시에 캡처하고 재생하는 것도 제한 없이 가능합니다.
음성 활동 감지(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는 이전 단계에서 얻은 사용 가능한 장치 배열에서 해당 장치의 인덱스입니다.
캡처 상태 확인하기
현재 사운드 웨이브가 오디오를 캡처 중인지 확인할 수 있습니다:
- 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);
StartCapture
를 통해 녹음을 시작할 때 엔진 측에서 약간의 끊김 현상이 발생할 수 있으므로, 캡처를 자주 전환하는 경우에 유용합니다. 먼저 캡처 자체를 시작한 후 음소거/음소거 해제를 수행해야 합니다.
약간의 프리즈 현상을 제거하는 것이 목표라면, 이 프리즈가 무시할 수 있을 정도의 시점에 캡처를 시작하는 것을 고려해볼 수 있습니다. 예를 들어 게임의 로딩 화면 중에 캡처를 시작하고, 바로 이후 캡처 가능한 사운드 웨이브를 음소거한 다음, 오디오 데이터를 끊김 없이 캡처해야 할 때 캡처 가능한 사운드 웨이브의 음소거를 해제할 수 있습니다.
완전한 예시
캡처 가능한 사운드 웨이브 사용의 완전한 구현 예시입니다:
- 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"
void UCaptureAudioClassExample::CaptureAudioExample()
{
// Create a capturable sound wave
CapturableSoundWave = UCapturableSoundWave::CreateCapturableSoundWave();
// Capture audio data from the input device with the specified device ID (0 in this case)
CapturableSoundWave->StartCapture(0);
// 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);
}