声波属性
您可以直接从声波中检索整个 PCM 缓冲区。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
TArray<float> PCMBuffer = ImportedSoundWave->GetPCMBufferCopy();
如果你需要将获取的 PCM 数据转换为字节,请查看这里。
要创建无缝的音频循环,你可以设置循环,以便在播放结束后自动将声波播放时间倒回零并重新播放。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetLooping(false);
您可以调整正在播放的声音的音量,以满足您的需求。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVolume(1.0f);
您还可以根据自己的喜好修改播放声音的音高。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetPitch(1.0f);
您可以设置字幕,即定义文本及其应显示的时间。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
TArray<FEditableSubtitleCue> Subtitles;
FEditableSubtitleCue Subtitle;
Subtitle.Text = FText::FromString("Example");
Subtitle.Time = 2.0f;
Subtitles.Add(Subtitle);
ImportedSoundWave->SetSubtitles(Subtitles);
您可以设置虚拟化模式,例如 Play When Silent,这允许声波在静音期间继续播放。如果您正在使用声音衰减,这将特别有用。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetVirtualizationMode(EVirtualizationMode::PlayWhenSilent);
</TabItem>
</Tabs>
***
如果需要更改导入的声音波形的采样率或通道数,可以使用适当的函数对音频数据进行重采样和混音。这样会修改整个声音波形数据,并相应地影响 `OnGeneratePCMData` 和 `OnPopulateAudioData` 委托的输出。
<Tabs groupId="languages">
<TabItem value="blueprint" label="Blueprint">

</TabItem>
<TabItem value="c++" label="C++">
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->ResampleSoundWave(44100);
ImportedSoundWave->MixSoundWaveChannels(2);
或者,如果你希望自动重采样并混合所有即将填充的音频数据,使其符合指定的目标采样率和通道数,你可以使用以下函数(这同样会影响 OnGeneratePCMData
和 OnPopulateAudioData
委托的输出)。
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
ImportedSoundWave->SetInitialDesiredSampleRate(44100);
ImportedSoundWave->SetInitialDesiredNumOfChannels(2);