Recently I was asked by a friend if I had an app that converts text to audio. So I dug out an old WPF app which I had created just for trying out the System.Speech
class library. This was a basic app that allowed the user to enter some text, read it aloud and save it to a file.
I started thinking about it, and came up with an easier and neater solution. The answer is right before your very eyes!
The web browser.
Every common web browser has an in-built capability to read text. This also enables the user to take advantage of online voices which aren’t installed on the device.
This can be achieved with Java Script. I therefore wrote a quick web page with a drop-down of the available voices, a list of languages and an input area.
The results were astonishing! Besides being a much quicker and lighter development experience, the browser’s online voices have the emphasises that the installed voices don’t have. This makes it sound much more like a real person speaking, instead of the choppy experience you get with the installed voices on your pc.
I’ve embedded the page below, with a simple answer machine style message as default, try it out here:
The browser has a built in speechSynthesis
which can be used to read text. The basic usage is as follows:
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voice = voices[6];
msg.volume = 1; // From 0 to 1
msg.rate = 1; // From 0.1 to 10
msg.pitch = 1; // From 0 to 2
msg.text = 'Welcome to this website';
msg.lang = 'en-GB';
speechSynthesis.speak(msg);
So if you ever want to do any text to audio, your best option (as well as being the easiest), is to use the browser.