Sunday, April 21, 2013

Introduction to Speech Capabilities in Windows Phone 8 – Part 3

Today I am going to post last part of this series, Hope Part1 and Part2 went well with you and hope you tried out the Speech Capabilities of Windows Phone 8. We already talked a lot about the different approaches of Text To Speech, In this we will see exactly reverse approach that its Speech To Text. Most of the time it is considered to be vary hard and difficult to implement, But with the given APIs in Windows Phone 8 makes them pretty easy to implement.So Lets see how you can build such app quickly.

Take a new Windows Phone 8 Application Project. Design I will leave that to you, Right now I have put this inside a Pivot item like this :

XAML :

<phone:PivotItem Header="Speech2Text" DoubleTap="LoadSpeechToText">               
</phone:PivotItem>

C# Code :

private async void LoadSpeechToText(object sender, RoutedEventArgs e)
       {
           SpeechRecognizerUI myspeechRecognizer = new SpeechRecognizerUI();
           myspeechRecognizer.Settings.ExampleText = "Ex. Call,Search,Run";
           myspeechRecognizer.Settings.ListenText = "Listening...";
           ….

       }

This will bring up the Popup where you need to suppose to talk or give command, To enable this functionality, you need to add two more lines of code

myspeechRecognizer.Settings.ReadoutEnabled = true;
myspeechRecognizer.Settings.ShowConfirmation = true;

Once you run this you will see our regular Speech Popup like this :

Launching

But just showing this screen is not sufficient, we need to capture the Text and display it to user, So for this we need to add few more lines of code

SpeechRecognitionUIResult Speechresult = await speechRecognizer.RecognizeWithUIAsync();
if (Speechresult.ResultStatus == SpeechRecognitionUIStatus.Succeeded)
{
    MessageBox.Show(Speechresult.RecognitionResult.Text);
}

Now you can see the result on a MessageBox, While doing the test I said “Nokia” and you can see the result on the screen.

Launchingheardsay

And here you can see the Result on MessageBox.  finalNow its your decision where you want this piece of code to be use, There are lot of Business cases where you can use this kind of Speech Recognition. You can use this to launch certain Commands in your application or you can use to record voice as well and convert to text for any purpose.Hope you will find this useful and thus quick end of my Speech Capability series, I have kept it short but in coming days I am going to put detail article on these features by taking a Business Case.Till then Happy Coding, I will soon post a Calendar related article and we will see how we can use that API at our best.

Vikram.

No comments: