Setting up Audio Communications in Unity with AudioStream
AudioStream is a very helpful unity asset which provides a multitude of options for streaming audio in Unity. In particular, AudioStream supports communications between C# and Icecast Audio Server, which is the key to our communications implementation.
Here's how to get everything setup in the Unity environment for bidirectional audio communications.
Step 1: Purchase or acquire a unity account linked to AudioStream.
- Here is the link to the asset: https://www.assetstore.unity3d.com/en/#!/content/65411
- Once you've acquired access, all that is needed is to open up the asset store in your unity project and navigate to the asset. At this point you can simply click download/import and the process should be simple.
- At first there may be error messages associated with the asset. Do not fret, as these will be corrected in the next step. :~)
Step 2: Import FMOD into your unity project.
- Visit the following url: https://www.fmod.com/.
- Create an FMOD account.
- Navigate to downloads->integrations and download and import FMOD Studio Unity Integrations.
Step 3: Create an AudioSource for input.
- Create a new audiosource in the gameobject hierarchy window. Create->Audio->AudioSource. Give it an appropriate name.
- Navigate to the scripts folder in the AudioStream library. Find and attatch the Audio Stream Script to your new audiosource.
- Now within the audiosource object find your Audio Stream script component and insert your icecast url (and mountpoint) into the source field. Set stream type to AUTODETECT. Audio input setup is now complete.
Step 4: Create an AudioSource for audio output.
- As above, create a new audiosource and give it an appropriate name.
- Navigate to the Scripts folder in your library and find the following two scripts. Audio Input stream and Icecast Source. Attach them to the newly created game object in the order specified.
- Now within the Icecast Source (Script) component of your game object, fill in the appropriate fields under [icecast source setup]. Ensure that your Hostname, Port, MountPoint, Password and Codec are all properly configured and audio output to your icecast server should be all set.