Speech Recognition In Windows Phone 8


In this article we will learn how to use speech recognition in Windows Phone 8. Speech recognition is a way to get input from the user. Once we have recognized the text spoken by the user we can use that text to perform various operations like activating a new app or writing it in a text area.

Speech Reorganization in Windows Phone 8

Speech recognition uses an async programming model so we need  to ensure that we must wrap the call to this API in an Async method. The simplest way of enabling an App for speech recognition involves the following procedure:

  1. Add the following using statement:

    using Windows.Phone.Speech.Recognition;
  2. Create a new instance of SpeechRecognizerUI class as in the following:

    SpeechRecognizerUI mic = newSpeechRecognizerUI();
  3. Show the recognizer UI to the user and start speech processing as in the following:

    SpeechRecognitionUIResult res = await mic.RecognizeWithUIAsync();
  4. Get the result of the recognition if it is not null or empty as in the following:


The following is the full code snippet illustrating the preceding.











    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation="Portrait"



    <!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent">


            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>



        <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

            <TextBlock Text="Demo" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

            <TextBlock Text="Speech Recognition" Margin="9,-7,0,0" FontSize="40"/>



        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">


                <RowDefinition Height="243*"/>

                <RowDefinition Height="406*"/>


            <Button Name="startBtn" Content="Start" Click="strtClick" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="225"/>

            <Button Name="popBtn" Content="Clear" Click="clear" HorizontalAlignment="Left" Margin="225,10,0,0" VerticalAlignment="Top" Width="221"/>

            <TextBlock Name="Result" Margin="0,87,0,153" Grid.RowSpan="2"></TextBlock>





C# Code Behind

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Navigation;

using Microsoft.Phone.Controls;

using Microsoft.Phone.Shell;

using Demo.Resources;

using System.Threading;

using Windows.Phone.Speech.Recognition;


namespace Demo


    public partial class MainPage : PhoneApplicationPage


        // Constructor

        public MainPage()





        private async void strtClick(object sender, RoutedEventArgs e)


            SpeechRecognizerUI mic = new SpeechRecognizerUI();

            SpeechRecognitionUIResult res = await mic.RecognizeWithUIAsync();

            if (res != null)


                Result.Text = res.RecognitionResult.Text;




        private void clear(object sender, RoutedEventArgs e)


            Result.Text = "";




The code above will launch the Speech recognition task. For the code above to work you need to provide your app the following two capabilities:


If you don't provide the following two permissions then your app will crash due to the lack of permissions to access the hardware.



That's all for this article. I hope you have found it useful. In case of any doubt feel free ask in the comments section.