1

Unity
When I click button "Record":
- Microphone.Start("Built-in Microphone", true, 10, 44100); When I click button "Pause":
- SavWav.Save (Application.persistentDataPath + "/Resources/storyrecord",aud.clip);

A files was saved with path : /storage/emulated/0/Android/data/com.owos.woftbattle/files/Resources/storyrecord

com.owos.woftbattle is my package. storyrecord is my file name.

So, can I open this with code?
This is my code : Resources.Load("file:///Resources/storyrecord");

It's not working.

Can anybody help me?

Programmer
  • 121,791
  • 22
  • 236
  • 328
Nghia Phan
  • 191
  • 2
  • 10

1 Answers1

1

The first thing to understand is that you cannot write or save to the Resources folder in a build(Android). The Resources folder can only be created from the Editor. Whatever you put inside the Resources folder will be the only thing there. You cannot be able to remove or add more files to the Resources folder. It's read-only once you build your app.

Secondly, saving your file as Application.persistentDataPath + "/Resources/storyrecord" will not work. Even if the file saved, that saved file is not in the Resources folder. Because it is not, Resources.Load cannot read it. The Resources.Load function can only read files that were added to it in the Resources folder from the Editor.

It's is important that you understand everything above for future reference and to avoid similar mistakes. If you want to save file during run-time, always save your data at: Application.persistentDataPath/YourFolderName then load it with the WWW class or one of the File API from System.IO namespace. The library you are using is saving it as ".wav" extension so you must use WWW API to load it.

Path to save Audio(Audio Path):

string tempPath = Path.Combine(Application.persistentDataPath, "Audio");
tempPath = Path.Combine(tempPath, "storyrecord.wav");

Save Audio:

SavWav.Save (tempPath ,aud.clip);

Load Audio as AudioClip:

IEnumerator loadAudio(string path)
{
    //Load Audio
    WWW audioLoader = new WWW(path);
    yield return audioLoader;

    //Convert it to AudioClip
    AudioClip aClip = audioLoader.GetAudioClip(false, false, AudioType.WAV);
}

Loading it requires a coroutine function so you must use the StartCoroutine function: StartCoroutine(loadAudio(tempPath));

Note:

On some Android devices, you must add "file://" before you can load the audio with the WWW class. If that's the case, simply add path = "file://" + path; to the first line of code in the loadAudio function above to fix the path.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Sorry for the late reply, I was too busy with several different projects. Thank you so much it worked :) . You saved my life ! – Nghia Phan Nov 27 '17 at 03:19