It is not easy to find good and free Text to Speech libraries for your .NET application. Even the solution in this MSDN blog, is of low-quality.
By far, the best TTS solution I have come across is AT&T Text-To-Speech Project. This is a project of AT&T Research. It is actually web-based and it is free. One should however not abuse the service and make a reasonable amount of calls to it.
The source code for consuming the service is presented below. It makes a simple HTTP POST request with the text and type of voice to use as input and returns the URL of the WAV file as a string.
private string speak(string theText, string theVoice)
{
try
{
string uriString = "http://192.20.225.55/tts/cgi-bin/nph-talk";
/* Create a new WebClient instance.*/
WebClient myWebClient = new WebClient();
/* Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.*/
System.Collections.Specialized.NameValueCollection myNameValueCollection = new System.Collections.Specialized.NameValueCollection();
string voice=theVoice;
string txt = theText;
string downloadButton = "DOWNLOAD";
/* Add necessary parameter/value pairs to the name/value container.*/
myNameValueCollection.Add("voice", voice);
myNameValueCollection.Add("txt", txt);
myNameValueCollection.Add("downloadButton", downloadButton);
/* Upload the NameValueCollection.*/
byte[] responseArray = myWebClient.UploadValues(uriString, "POST", myNameValueCollection);
string response = Encoding.ASCII.GetString(responseArray);
/*This code retrieves hyperlinks from a page*/
PODN.Net.Search.PageParser pp = new PODN.Net.Search.PageParser();
PODN.Net.Search.PageLink[] links = pp.RetrieveHyperlinks(response, uriString);
string fileToPlay=null;
if(links!=null && links.Length>0)
fileToPlay = "http://192.20.225.55" + links[0].URL;
return fileToPlay;
}
catch (Exception e) { /* ERROR */}
}
Later you can add a Windows Media Player control in your application and have it play the audio file. Your computer has now voice! As an example app you could download news and let the program read them back to you. You can find more details and the example application ('Tell me the news') in my 'Adding Speech to .NET applications' blog post here.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.