Home > Uncategorized > Create your own #AudioBooks with C#

Create your own #AudioBooks with C#


Say you’ve got a book in text format; for example a book from Gutenberg.org, and you’d like to convert it to mp3, so you can listen to the book – read by a machine, of course.

Here’s the code in C#

WebClient wc = new WebClient();
var strUrl = “{{Wherever your ebook text is}}”;
var strText = wc.DownloadString(strUrl);
var strPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
using (SpeechSynthesizer reader = new SpeechSynthesizer())
reader.Volume = 100;
reader.Rate = 0; //medium
MemoryStream ms = new MemoryStream();
reader.SetOutputToWaveStream(ms);//do speaking
ConvertWavStreamToMp3File(ref ms, strPath + @”\54135.mp3″);

You need to install the Nuget package: Install-Package NAudio.Lame for the mp3 functionality. ConvertWavStreamToMp3File is defined as:

public static void ConvertWavStreamToMp3File(ref MemoryStream ms, string savetofilename)
//rewind to beginning of stream
ms.Seek(0, SeekOrigin.Begin);

using (var retMs = new MemoryStream())
using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, LAMEPreset.VBR_90))

To give an idea of filesizes, I used an input file of 33,790 words, which resulted in a WAV file on 705MB, and Mp3 file of 63 MB.

Which you can hear here:

Of course, if you prefer to read a Gutenberg book onscreen, then you can use our app:


This can further be converted to a FLV using FFMPEG ;

ffmpeg -i audio-book.jpg -i 54135.mp3 final.flv

Which takes about 2 minutes, an generates a 73 MB FLV file.

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: