I'm making a cross platform application, with the game engine Unity, that simply takes images and audio files (.ogg) from a bucket made with the Amazon Simple Storage Service (Amazon S3). I'm having a problem converting audio files, represented in bytes, to AudioClips.
I have already tried the solutions from both links:
Noisy audio clip after decoding from base64
But both solutions doesn't resolve my problem, there is still the static sound after the conversion process from bytes to array.
Another solution I tried is to use the UnityWebRequestMultimedia and taking the audio from the url that every single object has in the bucket. This solution works only on the standalone version of the application (PC,Linux,Mac OS). When I try my application on an smartphone, with Android as OS, the UnityWebRequestMultimedia doesn't send the request and that's why I'm trying again to convert the bytes of the object taken from S3 to audioclip.
Every Audio file on S3 is an .ogg file with the following properties:
//Method that takes the bytes of the audioclip
private AudioClip GetMediaBytesFromS3 (Amazon.Runtime.AmazonServiceResult<GetObjectRequest,GetObjectResponse> ServiceResult,string nameOfAudio)
{
//Take the bytes of the audio
byte[] mediaBytes = GetBytesFromMultimediaObject(ServiceResult);
//Make a float array
float[] floatMediaBytes = new float[mediaBytes.Length / 4];
for(int i=0;i<floatMediaBytes.Length; i++)
{
//Check if the architecture use the LittleEndian ordering of Bytes
if(BitConverter.IsLittleEndian)
{
Array.Reverse(mediaBytes,i*4,4);
}
floatMediaBytes[i] = ((float) BitConverter.ToInt16(mediaBytes,i*4)) / 0x80000000;
}
//Make a new audioclip
AudioClip clipAudio = AudioClip.Create(nameOfAudio,floatMediaBytes.Length,1,16000,false);
//See if the data are set
if(clipAudio.SetData(floatMediaBytes,28))
{
return clipAudio;
}
return null;
}
I simply want the audio be played correctly without the static noise.