Loading mp3 to AudioClip at runtime in Unity - c#

How can I load mp3 file from filesystem to AudioClip object?
I can load ogg or wav using WWW class, and play it with Audio Source component, but on Windows mp3 is not supported.
Or use an external library, like NAudio. But I'm using AudioSource.GetSpectrumData() to visualize some game elements, and can't find similar method in NAudio.
What should i use to play audio from file, and analyze it?

Related

How can I use mp3 files in Windows Phone 8?

in my windows phone gaming apps, I have to use lots of sound. Now I have seen that Windows phone does not support mp3 files. So I need to use the wav files. Any mp3 file which is just 500 kb size in mp3 format, when convert that to ".wav" it becomes min 2.5MB. It's actually eating up my apps size and unnecessarily the size of my apps is getting bigger.
Anyone know how can I use the mp3 file? In my solution I have a Asset folder and inside this folder all the ".wav" files are located.
How I am doing this let me write a code
SoundEffect effect;
Iinside constructor-
{
...
var soundFile = "Assets/Jump.wav";
Stream stream = TitleContainer.OpenStream(soundFile);
effect = SoundEffect.FromStream(stream);
And in the code
effect.Play();
Is there any better approach. In some thread I come to know that doing this is not a better way coding as it creates object and used up the system space. Please suggest what to do, how do I add mp3 files and write better code for working with sound files.
you can use BackgroundAudioPlayer to play your wav and mp3 files. SoundEffect class cannot play mp3 data
Go through this it's an entire app on it's own.
Background Audio WP
To use an MP3 file you would have to decode the MP3 into PCM in memory, and use that resulting stream in the SoundEffect.FromStream method.
Another thing you could try is encoding the wav files as ADPCM. This usually compresses the wave file at ratio of 4:1. If you can't use the stream directly, decoding of ADPCM is much more straightforward than decoding an mp3 file.
And one more thing you could try to save space is converting the uncompressed wave files into mono, and a lower sampling rate. You can perform listening tests on the sounds after the conversion to make sure that the loss in quality is acceptable or not.

how to add sound in video with.avi extention in c#.net

I'm developing the project on videowatermarking using c#.net. I'm creating the video from .bmp file.
I'm able to create the video using avi manager in .avi extension but not able to add the sound to it video is created without sound....taking sound of .wav extension
Have a look at this, may be this is useful for you:
http://www.codeproject.com/Articles/7388/A-Simple-C-Wrapper-for-the-AviFile-Library

open audio formats and audio synthesis using NAudio

How can I open different audio formats(except .mp3 and .wav) using Naudio and C#?
How can I create audio synthesis unsing Naudio and C#?(I mean how to get the sound frequency and other data necesary for audio synthesis).
P.S. I've looked at this tutorial series
http://opensebj.blogspot.com/2009/02/introduction-to-using-naudio.html
and this one
http://www.giawa.com/tutorials/?p=19o
In addition to MP3 and WAV, NAudio can also open AIFF and WMA files with the AiffFileReader and WmaFileReader classes. Beyond that, you will have to write your own WaveStream derived class to read other formats.
See my tutorial on how to play a sine wave in NAudio, which will show you the basics of how to get started with audio synthesis in NAudio.

How to overlay audio file on .wmv video file using c#?

I want to record video and audio files using C#. After recording of audio + video i want to merge them. There can be only one video file and 10 audio file. I want this ten files to overlay on one video file.
I am assure that i want video file in .wmv format. Can you tell me i should record audios in which format so later i can overlay those audio files on .wmv format video file?
Also please let me know how to overlay audio file on .wmv video file?
Hope i will get prompt reply for this
You can use DirectShow Editing Services (DES) to do it. DirectShowLib should provide DES support in C#. Using it, create a timeline with video group (1 track) and audio group (several tracks if you need to overlay/mix some audios, i.e. hear more than one at a time). Place your video and audio files on the timeline in desired positions. Then tell DES to create a DirectShow graph and you'll get one video and one audio output pin. Connect them to ASF writer to save result to WMV.

how do i merge two audio files and one video file in to a video file using c#?

i wrote a program in c# using directshow , that captures all devices' audios , and video from single device (webcam or external camera) , now that my requirement is to merge selected audio files with one video file and i can not get it done in c#.
so i need a program or libraries that merges one(or several) audio file(s) and one video file and save it as an avi VIDEO file ,, both audio file and video files are in avi format.
You should check this out A Simple C# Wrapper for the AviFile Library

Categories

Resources