Jump to content

Recommended Posts

Posted

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. Oneshould however not abuse the service and make a reasonable amount ofcalls 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.NameValueCollectionmyNameValueCollection = newSystem.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.

 

 

More...

 

View All Our Microsoft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...