Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Playing ALaw memorystream

$
0
0

1st of all, sorry for the double post, it was not done on purpose.

I managed to save a wave file to disk and this is cool, but it's not my scope.

The raw data comes from MS TTS (Text to speech) and it is working as expected. In order to test the code, please add a reference to System.Speech

and add 

using System.Speech;

using System.Speech.AudioFormat;

using System.Speech.Synthesis;

            MemoryStream memStream = new MemoryStream();

            SpeechSynthesizer speaker = new SpeechSynthesizer();
            speaker.Rate = 0;
            speaker.Volume = 100;
            speaker.SelectVoice("Microsoft Sam");

            SpeechAudioFormatInfo ALawFormat = new SpeechAudioFormatInfo(EncodingFormat.ALaw, 8000, 8, 1, 1, 2, null);

            speaker.SetOutputToAudioStream(memStream, ALawFormat);

            speaker.Speak("Hello world!");

            ByteArrayToFile(@"C:\temp\MyRawFile.raw", memStream.ToArray());

            WaveFormat format = WaveFormat.CreateALawFormat(8000, 1);

            FileStream fs = new FileStream(@"C:\temp\MyRawFile.raw", FileMode.Open);

            using (RawSourceWaveStream reader = new RawSourceWaveStream(fs, format))
            {
                WaveFileWriter.CreateWaveFile(@"C:\temp\MyRawFile.wav", reader);
                reader.Close();
            }

            fs.Close();

 

when speaker.speak() is executed, memStream contains my audio file, raw data, ALaw encoded. If I save the file (using ByteArrayToFile) and then use Audacity, the file plays perfectly well (Microsoft Sam voice is crap, but we overlook it now).

The example provided here is to be clear enough on what kind of audio I'm working with.

So, my question is: what should I do in order to play that memStream with NAudio?

This is a big deal to me, since I can't open the VS solution (I don't have vs 2010, am stuck to 2008) and can't find any kind of documentation around this simple task.

Can anyone please help me? I'm a bit frustrated :(


Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>