Play MP3 from stream - c#

Is there any way to play MP3 directly from a memory stream (without any temp. files) using VB.NET or C#? or play from SQLCe database?
Thanks

I'll suggest you try Mp3Sharp. It is a port of JavaLayer and it is written in C#. I am currently using it and SlimDX to play ShoutCast Mp3 streams. So far it works very well. There is an Mp3Stream class which you use to read the stream and return a predetermined number of PCM bytes. You can write those bytes to a DirectSound buffer for playback if you wish.

IrrKlang can also do this for you.

Related

convert audio to bytes without recording c#

I am currently developing a c# Windows Form. My intention is to create a form that can make calls to other PCs in the same network.
So far I have found solutions that record the audio from my microphone and then convert it to bytes and send it using Tcp sockets. The thing is, is there a way to directly convert the audio to bytes and send it through a socket without recording the audio in a file and then send it.
Thanks in advance.
would converting the record to a memorystream be what your looking for?
if so you want this How to record audio using naudio onto byte[] rather than file
You can then write the stream to a tcpsocket. (you could write the thing direct to networkstream but i would consider it bad practice)
It would be wise to write samplerate*3 just in case of lantcy issues.

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.

Appending to a WaveStream

I am trying to stream sound using Naudio. The thing I am having trouble with is that I can't write to a WaveStream. I tried making a queue of smaller WaveStream but I don't think this is not the way to go. How can I stream an mp3 file, or wave file over the network and start playing it even if it is not completely transferred?
Have a look at the BufferedWaveProvider, it can be used as an input to WaveOut and allows you to queue up buffers for playback. You would however need to decode the MP3 file frame by frame yourself using the MP3Frame class, as the MP3FileReader expects to be able to reposition to the end.

NAudio - Streaming byte[] of wav makes it play slow

I am trying to read bytes from a wav file and send it across to a stream but it plays slowly.
Could you please help me to know the right way of populating the byte[]?
Thanks for you help.
are you using NAudio to both read the WAV file and play the data?
you need to make sure you use the same WaveFormat at both ends

Converting mp3 bitrates using lame_enc.dll or similar

I need to programatically convert mp3's of any bitrate to a standard bitrate for streaming audio using c#.
Currently a buffer is populated with mp3 data from disk and then send out to the "listeners" at what should be a constant speed (the broadcast), but the mp3's could be of any bitrate. This makes timing extremely difficult and should rather be streamed at a standard bitrate instead of a bitrate dictated by the mp3 itself.
Lame seems to be the right encoder for the job, but any documentation or sample code only seems to be concerned with converting from wav samples to mp3. Not mp3 to mp3. The exe wrapper can do the bitrate conversion, but completely without any clue as to what gets passed to beEncodeChunk().
Has anyone had any experience in doing this kind of thing with lame or any similar encoder?
Do i need to decode to wav then encode back to mp3 to achieve what i'm after?
I welcome any links or advice with open arms.
Thanks
you have to decode the mp3 to wav, then re-encode it to the new bitrate

Categories

Resources