This sample demonstrates the basics of speech recognition for speech-to-text functionality, in addition to the fundamentals of working with Windows Azure Mobile Services to retrieve and store data in a Windows Azure database table. When the app runs, it authenticates a user by using a Microsoft Account, retrieves the user’s notes that are stored in the Windows Azure database, and gives the user access to record and store new notes in the database, and delete existing notes. This sample shows you how to do the following:

  • Use Mobile Services to authenticate a user by using a Microsoft Account.

  • Use Mobile Services to store, retrieve, and delete data from a Windows Azure database table.

  • Generate text from speech using the Windows Phone speech recognition APIs and the predefined dictation grammar.

This sample uses the Windows Phone speech recognition APIs and the Windows Azure Mobile Services SDK. For more info about speech recognition in Windows Phone 8, see Speech recognition for Windows Phone 8. For more info about the Windows Azure Mobile Services SDK, visit Windows Azure Mobile Services.

 

Steps to build and run the sample

  1. Create a Windows Azure account that has the Mobile Services feature enabled. For details about creating a free account and enabling preview features, see Create a Windows Azure account and enable preview features.

  2. Create a Mobile Service and a Windows Azure database to use for the sample. For info about how to do this, see the section Create a new mobile service in the Get started with Mobile Services tutorial.

    Note:

    The Get started with Mobile Services tutorial covers more than is needed for this sample. For this sample you only need to perform the steps specified in the Create a new mobile service section, using your chosen mobile service and database names.

  3. Set up a database table named VoiceNote to use in the sample.

    1. Log on to the Windows Azure management portal, and then click the Mobile Services tab.

    2. Click the name of your mobile service.

    3. Click the DATA tab.

    4. Click the CREATE button at the bottom of the page.

    5. Name the table VoiceNote.

    6. When you set the permissions for the table, use the Only Authenticated Users option for all actions.

    Note:

    For the purposes of this sample, the table must be named VoiceNote.

  4. If it’s not already installed, install Visual Studio Express 2012 for Windows Phone.

  5. Install the Windows Azure Mobile Services SDK.

  6. Register the sample app for Microsoft Account authentication using the steps shown in Get started with authentication in Mobile Services. Although other account types are possible, the sample is currently configured to use a Microsoft Account for authentication.

    Note:

    The code for authentication is included in the sample, you only need to perform the steps in the Register your app for authentication and configure Mobile Services section.

  7. Update the Windows Azure database table read and update scripts to support authentication.

    1. Log on to the Windows Azure management portal, and then click the Mobile Services tab.

    2. Click the name of your mobile service.

    3. Click the DATA tab.

    4. Select the VoiceNote table.

    5. Click the SCRIPT tab.

    6. In the Action list OPERATION click Insert, and then replace the default code with the following code example.

         
      function insert(item, user, request) {
          item.userId = user.userId; 
          item.createdAt = new Date();
          request.execute();
      }
    7. In the Action list OPERATION click Read, and then replace the default code with the following code example.

         
      function read(query, user, request) {
          query.where({ userId: user.userId });
          request.execute();
      }
  8. Add the Azure Application Key and mobile service URL to the sample App.Xaml.cs file as shown in the following code example.

       
    //Static MobileServiceClient object for use by the application
    //Initialize with your specific mobile service URL and application key
    public static MobileServiceClient MobileService = new MobileServiceClient(
       "Your mobile service URL",
       "Your application key");
    Note:

    To find the mobile service URL and Azure Application Key, go to the Windows Azure management portal and click the Mobile Services tab. The URL is specified in the central table. To display the keys, click the Manage Keys button at the bottom of the page.

  9. Build the sample.

Build the sample

  1. Start Visual Studio Express 2012 for Windows Phone and select File > Open > Project/Solution.

  2. Go to the directory in which you unzipped the sample. Double-click the Visual Studio Express 2012 for Windows Phone solution (.sln) file.

  3. Select Build > Rebuild Solution to build the sample.

Run the sample

  1. To debug the app and then run it, press F5 or use Debug > Start Debugging.

  2. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.

See also