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.