Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mirko15 · Jul 14, 2016 at 04:34 PM · c#unity 5audiowww

How to import wav file trough script from Project folder?

I have app when i press button it should import .wav file and on other button it plays that wav file. it needs to be specialy song with for example "beat.wav". i tried with WWW but cant figure out how to get to project folder, no assets folder but project!

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zitoox · Jul 14, 2016 at 05:42 PM 0
Share

Why do you want to make this?

avatar image mirko15 Zitoox · Jul 14, 2016 at 06:40 PM 0
Share

Im making a little music game, and i made a script that saves wav file of microphone.Record()... After button for save is pressed it saves it in project folder, not in assets folder... And now i need a way to set that as audio clip for audio source attached to one of my game Objects.

avatar image wojtask12 · Jul 14, 2016 at 08:09 PM 0
Share

Are you using unity's implementation of microphone recording? https://docs.unity3d.com/ScriptReference/$$anonymous$$icrophone.html

If you do, function $$anonymous$$icrophone.Start return AudioClip object which you can use with an AudioSource

avatar image mirko15 wojtask12 · Jul 15, 2016 at 12:04 PM 0
Share

Thanks, but its not all for mic, i have and sound wav maker something, that cant be played like that...

avatar image Justice-V18 · Jul 14, 2016 at 09:02 PM 0
Share

Here is a script that I made hopefully it helps out

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 
 public class AudioAccessor: $$anonymous$$onoBehaviour 
 {
     //In this case I never looked for the game folder ins$$anonymous$$d i checked for the audio files in "my documents"
     private string GamePath;
     private DirectoryInfo GameDirectory;
 
     //Audio info
     private DirectoryInfo AudioDirectory;
     private string AudioPath;
 
     private FileInfo[] AudioFilesFound;
     private AudioClip clip;
     public List<AudioClip> LoadedAudioWeapons = new List<AudioClip>();
 
     void Start()
     {
         CheckFoldersAndLoad$$anonymous$$odObjects();
     }
     
     public void CheckFoldersAndLoad$$anonymous$$odObjects () 
     {
         if(File.Exists(System.Environment.SpecialFolder.$$anonymous$$yDocuments + "\\TheGamesName") == false)//if there was nothing found in my documents then create them
         {
             CreateFolder();
         }
         else //Otherwise if the stuff exists just the the path
         {
             GameDirectory = System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.$$anonymous$$yDocuments) + "\\TheGamesName");
             GamePath = GameDirectory.FullName.ToString();
         }
 
         //Load all objects from folders here
         GetAudioFromFolder();
     }
 
     //Creation of files
     private void CreateFolder()
     {
         GameDirectory   = System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.$$anonymous$$yDocuments) + "\\TheGamesName");
         GamePath        = GameDirectory.FullName.ToString();
     }
 
     private void GetAudioFromFolder()
     {
         AudioFilesFound = GameDirectory.GetFiles("*.ogg*");//Gets all files with the format ".ogg"
 
         for (int k = 0; k < AudioFilesFound.Length; k++)
         {
             StartCoroutine(LoadAudioWeapons(AudioFilesFound[k].ToString()));
         }
     }
 
     private IEnumerator LoadAudioWeapons(string fileName)
     {
         WWW www = new WWW("File:///" + fileName);
         yield return www;
 
         if(Path.GetExtension(fileName).ToUpper() == ".OGG") 
             clip = www.GetAudioClip(true, false, AudioType.OGGVORBIS);
 
         while (clip.loadState == AudioDataLoadState.Loading)
             yield return www;
 
         clip.name = Path.GetFileName(fileName);
         LoadedAudioWeapons.Add(clip);
     }
 }

It accesses the files from my documents, you might want yo change the file path if you want to access your project folder, i think its Application.dataPath but I'm to lazy to look XD

Another note, I'm not to sure if you can import .wav so you just going to have to double check as I originally wanted to import .mp3 but unity wouldn't allow it.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityWebRequest hangs on isDone but not always 1 Answer

Is it possible to access the speaker in the DualShock 4 controller without the PS4 kit? 1 Answer

Problem with audio 1 Answer

Why does loading music files at runtime in android using www class takes a lot of time? 0 Answers

How to do a FFT in Unity? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges