Hello, I have an mobile game that needs to record audio using the microphone and then upload these clips to the server. Been looking for a way to do this but I just can’t figure how, There are examples of images being uploaded but when I follow through with the same method for Audio then that saves a blank file. I used SavWav and I was able to save the file to local memory but I am not able to figure how to upload it to a sever. Right now I have it working like this (pretty sure this is wrong)
public bool UploadToWeb(AudioClip clip)
{
var filename = "sample";
if (!filename.ToLower().EndsWith(".wav"))
{
filename += ".wav";
}
var samples = new float[clip.samples];
clip.GetData(samples, 0);
Int16[] intData = new Int16[samples.Length];
Byte[] bytesData = new Byte[samples.Length * 2];
int rescaleFactor = 32767;
for (int i = 0; i < samples.Length; i++)
{
intData <em>= (short)(samples _* rescaleFactor);_</em>
* Byte[] byteArr = new Byte[2];*
_ byteArr = BitConverter.GetBytes(intData*);
byteArr.CopyTo(bytesData, i * 2);
}
StartCoroutine (UploadFile (bytesData));
}*_
public IEnumerator UploadFile(Byte[] uploadBytes) {
* WWWForm form = new WWWForm();*
* form.AddBinaryData(“fileUpload”, uploadBytes, “sample.wav”, “audio/wav”);*
* WWW w = new WWW(weburl, form);*
* yield return w;*
* if (!string.IsNullOrEmpty(w.error)) {*
* Debug.Log(w.error);*
* }*
* else {*
* Debug.Log(“Finished Uploading Screenshot”);*
* }*
}
Here is the php script I was trying to use.
<?php
byteArray = _POST[‘audioArray’];
$myfile = fopen(“sine.wav”, “wb”) or die(“Unable to open file!”);
fwrite($myfile, $byteArray);
fclose($myfile);
?>
Can someone please help me with how is this meant to be done?