NuGet Project Uncovered: TranslatorService.Speech

If you are coming to this series of posts for the first time you might check out my introductory post for a little context.

TranslatorService.Speech is a small little wrapper around the Bing text to speech API. You will need to get a Bing api key to leverage this.

Below is a sample usage of the library.

SpeechSynthesizer speech = new SpeechSynthesizer(APP_ID);   
// To obtain a Bing Application ID, go to http://msdn.microsoft.com/en-us/library/ff512420.aspx  
 
string text = "Have a nice day!"; 
string language = "en"; 
 
using (Stream stream = speech.GetSpeakStream(text, language)) 
{     
    using (SoundPlayer player = new SoundPlayer(stream)) 
        player.PlaySync(); 
}

I threw that into a quick test and was quite impress with how fast it worked.

Unfortunately I tried to translate a larger ?paragraph? or so of text and saw.

System.Net.WebException : The remote server returned an error: (400) Bad Request.

at System.Net.HttpWebRequest.GetResponse()

at TranslatorService.Speech.SpeechSynthesizer.GetSpeakStream(String text, String language)

at NuGetTestProject.Sample.SampleTest() in Class1.cs: line 14

I didn?t take the time to diagnose why, whether it?s a Bing problem or this library.

Some other observations:

  • + It supports some Async methods as well
  • – The Async methods don?t support the standard APM so I couldn?t easily wrap a task around. (I know there are some ways to make it work, but it?s not out of the box easy?)

One thought on “NuGet Project Uncovered: TranslatorService.Speech

  1. I worked on a large project using the MS translator API and was really impressed with the API functionality, which includes Speak().  Worth checking out – http://www.microsofttranslator.com/dev/

Comments are closed.

Proudly powered by WordPress | Theme: Code Blog by Crimson Themes.