Transcode audio
Transcoding formats
You can transcode audio from one RAW or Encoded format into another using the corresponding functions.
- Blueprint
- C++
// From encoded file to encoded file
URuntimeAudioTranscoder::TranscodeEncodedDataFromFile(TEXT("C:/Folder/AudioFrom.mp3"), ERuntimeAudioFormat::Auto,
TEXT("C:/Folder/AudioTo.ogg"), ERuntimeAudioFormat::OggVorbis,
100, FRuntimeAudioExportOverrideOptions(),
FOnEncodedDataTranscodeFromFileResultNative::CreateWeakLambda(this, [](bool bSucceeded)
{
// Handle the result
}));
// From encoded buffer to encoded buffer
TArray64<uint8> EncodedDataFrom;
URuntimeAudioTranscoder::TranscodeEncodedDataFromBuffer(EncodedDataFrom, ERuntimeAudioFormat::Auto,
ERuntimeAudioFormat::Wav,
100, FRuntimeAudioExportOverrideOptions(),
FOnEncodedDataTranscodeFromBufferResultNative::CreateWeakLambda(this, [](bool bSucceeded, const TArray64<uint8>& EncodedData)
{
// Handle the result
}));
// From RAW file to RAW file
URuntimeAudioTranscoder::TranscodeRAWDataFromFile(TEXT("C:/Folder/AudioFrom.raw"), ERuntimeRAWAudioFormat::Int16,
TEXT("C:/Folder/AudioTo.raw"), ERuntimeRAWAudioFormat::Float32,
FOnRAWDataTranscodeFromFileResultNative::CreateWeakLambda(this, [](bool bSucceeded)
{
// Handle the result
}));
// From RAW buffer to RAW buffer
TArray64<uint8> RAWDataFrom;
URuntimeAudioTranscoder::TranscodeRAWDataFromBuffer(RAWDataFrom, ERuntimeRAWAudioFormat::Int8,
ERuntimeRAWAudioFormat::Int32,
FOnRAWDataTranscodeFromBufferResultNative::CreateWeakLambda(this, [](bool bSucceeded, const TArray64<uint8>& RAWData)
{
// Handle the result
}));
Convert float array to bytes
You can convert a float array (e.g., 32-bit float PCM data) into a byte array. This is useful when your audio data needs to be in bytes, such as for network transmission or certain processing systems. This conversion is often required when using delegates like OnGeneratePCMData or OnPopulateAudioData, as they output float PCM data.
- Blueprint
- C++
// Assuming FloatArray is an array of floats (such as 32-bit float PCM data)
TArray<float> FloatArray;
// Synchronous
TArray<uint8> ByteArray = URuntimeAudioUtilities::ConvertFloatArrayToBytes(FloatArray);
// Asynchronous
URuntimeAudioUtilities::ConvertFloatArrayToBytesAsync(FloatArray,
FOnConvertFloatArrayToBytesResultNative::CreateWeakLambda(this, [this](const TArray<uint8>& ByteArray)
{
// Handle the result
}));