{"id":703,"date":"2011-02-24T04:45:00","date_gmt":"2011-02-24T04:45:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2011\/02\/24\/visual-basic-windows-phone-7-series-2-how-to-create-a-microphone-application-for-windows-phone-7\/"},"modified":"2024-07-05T12:40:30","modified_gmt":"2024-07-05T19:40:30","slug":"visual-basic-windows-phone-7-series-2-how-to-create-a-microphone-application-for-windows-phone-7","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/visual-basic-windows-phone-7-series-2-how-to-create-a-microphone-application-for-windows-phone-7\/","title":{"rendered":"Visual Basic Windows Phone 7 Series #2. How to create a microphone application for Windows Phone 7"},"content":{"rendered":"<p><span style=\"font-size: small\">In our <\/span><a href=\"http:\/\/blogs.msdn.com\/b\/vbteam\/archive\/2011\/02\/23\/how-to-create-a-mini-browser-application-for-windows-phone-7.aspx\"><span style=\"font-size: small\">last post<\/span><\/a><span style=\"font-size: small\">, I explained how to create a mini browser for Windows Phone 7. In this blog, I want to share a sample that will help you to create a microphone application for Windows Phone 7. This application will have the feature to capture audio from a microphone and then play back the captured audio. I will now demonstrate how easy it is to create a microphone application for Windows Phone 7, using Visual Basic for Windows Phone Developer Tools. <\/span><\/p>\n<p><span style=\"font-size: small\">The microphone application can be created in <b>4 simple steps as follows<\/b>:<\/span><\/p>\n<ol>\n<li><span style=\"font-size: small\">Create a sample application and add controls <\/span><\/li>\n<li><span style=\"font-size: small\">Add event handlers <\/span><\/li>\n<li><span style=\"font-size: small\">Build and debug the application <\/span><\/li>\n<li><span style=\"font-size: small\">Rebuild in the release mode before publishing <\/span><\/li>\n<\/ol>\n<p><i><span style=\"font-size: small\">Prerequisites:<\/span><\/i><\/p>\n<ul>\n<\/ul>\n<ul>\n<li><span style=\"font-size: small\"><i>Visual Studio 2010 Professional, Premium,\nor Ultimate. If you do not have any of the releases, you can download any of\nthe following trial versions as per your preference: <\/i><a href=\"http:\/\/www.microsoft.com\/downloads\/en\/details.aspx?FamilyID=26bae65f-b0df-4081-ae6e-1d828993d4d0&amp;displaylang=en\"><i>Professional<\/i><\/a><i>, <\/i><a href=\"http:\/\/www.microsoft.com\/downloads\/en\/details.aspx?FamilyID=7038e207-329c-4006-b620-16d1af1c42c1&amp;displaylang=en\"><i>Premium<\/i><\/a><i>, or <\/i><a href=\"http:\/\/www.microsoft.com\/downloads\/en\/details.aspx?FamilyID=e2a1a098-995e-4468-816d-7fdbe0a64f38&amp;displaylang=en\"><i>Ultimate<\/i><\/a><i>.<\/i><\/span><\/li>\n<li><span style=\"font-size: small\"><a href=\"http:\/\/www.microsoft.com\/downloads\/en\/details.aspx?FamilyID=04704acf-a63a-4f97-952c-8b51b34b00ce&amp;displaylang=en\"><i>Windows Phone Developer Tools\nRTW<\/i><\/a><\/span><\/li>\n<li><span style=\"font-size: small\"><a href=\"http:\/\/www.microsoft.com\/downloads\/en\/details.aspx?FamilyID=4e97ea70-e479-4c05-814f-639d71690e5d&amp;displaylang=en\"><i>Visual Basic\nfor Windows Phone Developer Tools &#8211; RTW<\/i><\/a><em><br \/><\/em><\/span><span style=\"font-size: small\"><em>Note: You can install the newer version- <\/em><em><a href=\"http:\/\/www.microsoft.com\/downloads\/en\/details.aspx?FamilyID=77586864-ab15-40e1-bc38-713a95a56a05&amp;displaylang=en\">Windows Phone Developer Tools 7.1 Beta<\/a>\n instead of the above mentioned two tools as it will take comparatively\nless time. However, this sample was created using the previous version.<\/em><\/span><\/li>\n<\/ul>\n<ul>\n<\/ul>\n<p><span style=\"font-size: small\">To create the microphone application, let&rsquo;s follow the 4 simple steps mentioned earlier:<\/span><\/p>\n<h3><b>Step 1 &#8211;<\/b><b> <\/b><b>Create a sample application and add controls<\/b><\/h3>\n<h4><b>Create a sample application<\/b><\/h4>\n<ol>\n<li><span style=\"font-size: small\">Create a new project and browse to the &ldquo;Silverlight for Windows Phone&rdquo; node. <\/span><\/li>\n<li><span style=\"font-size: small\">Select the &ldquo;Windows Phone Application&rdquo; template. <\/span><\/li>\n<li><span style=\"font-size: small\">Enter a name for the application.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0023.jpg\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/1563.Select_App_Initial.bmp\" width=\"537\" border=\"0\" height=\"477\" \/> <\/li>\n<li><span style=\"font-size: small\">Click OK. The MainPage.xaml page is displayed.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0043.jpg\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/2021.Main20Page.bmp\" width=\"533\" border=\"0\" height=\"429\" \/> <\/li>\n<li><span style=\"font-size: small\">In Solution Explorer, right-click the application name and then select Add Reference.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0063.jpg\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/0285.Solution20Explorer.bmp\" border=\"0\" \/> <\/li>\n<li><span style=\"font-size: small\">Select Microsoft.Xna.Framework from the list, and then click Ok.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0083.jpg\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/1205.XNA_.bmp\" width=\"451\" border=\"0\" height=\"377\" \/> <\/li>\n<\/ol>\n<p><b>&nbsp;<\/b><\/p>\n<h4><b>Add controls<\/b><\/h4>\n<p><img decoding=\"async\" src=\"\" border=\"0\" \/><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0103.jpg\"><\/a><\/p>\n<ol>\n<li><span style=\"font-size: small\">Click the MY APPLICATION text. In the Properties window, change the text property to &ldquo;SILVERLIGHT MICROPHONE SAMPLE&rdquo;. <\/span><\/li>\n<li><span style=\"font-size: small\">Click the page name text. In the Properties window, change the text property to &ldquo;press record&rdquo;. <\/span><\/li>\n<li><span style=\"font-size: small\">In Solution Explorer, right-click the application name and add a new folder. <\/span><\/li>\n<li><span style=\"font-size: small\">Rename the new folder as &ldquo;Images&rdquo;, and add the required icon images to the folder. <\/span><\/li>\n<li><span style=\"font-size: small\">From the toolbox, drag and drop the Image control to the design surface. <\/span><\/li>\n<li><span style=\"font-size: small\">Click the Image control. In the Properties window, change the text property to &ldquo;StatusImage&rdquo;. <\/span><\/li>\n<li><span style=\"font-size: small\">Change the source property of the Image control to link it to the icon image you added in the Images folder. <\/span><\/li>\n<li><span style=\"font-size: small\">Add the following XAML code to create the record, play, and stop buttons. This code also links the buttons to the respective icon images from the Images folder. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 92.01%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 97px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\"><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">phone<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">PhoneApplicationPage.ApplicationBar<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">shell<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">ApplicationBar<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IsVisible<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"True\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IsMenuEnabled<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"False\"&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">shell<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">ApplicationBar.Buttons<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">shell<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">ApplicationBarIconButton<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> x<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Name<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"recordButton\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"record\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IconUri<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"\/Images\/record.png\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Click<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"recordButton_Click\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IsEnabled<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"True\"\/&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">shell<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">ApplicationBarIconButton<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> x<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Name<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"playButton\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"play\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IconUri<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"\/Images\/play.png\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Click<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"playButton_Click\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IsEnabled<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"False\"\/&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">shell<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">ApplicationBarIconButton<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> x<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\">Name<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"stopButton\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Text<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"stop\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IconUri<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"\/Images\/stop.png\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> Click<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"stopButton_Click\"<\/span><span style=\"font-family: 'Courier New';color: red;font-size: 8.5pt\"> IsEnabled<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">=\"False\"\/&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;\/<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">shell<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">ApplicationBar.Buttons<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;\/<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">shell<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">ApplicationBar<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&gt;<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&lt;\/<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">phone<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">:<\/span><span style=\"font-family: 'Courier New';color: #a31515;font-size: 8.5pt\">PhoneApplicationPage.ApplicationBar<\/span><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">&gt;<\/span><\/p><\/pre>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p><span style=\"font-size: small\">Your application now looks like this:<\/span><\/p>\n<p><span style=\"font-size: small\"><span><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/7181.Application.bmp\" border=\"0\" \/><\/span><\/span><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0133.jpg\"><\/a><s><\/s><\/p>\n<p><b>&nbsp;<\/b><\/p>\n<h3><b>Step 2 &#8211; Add event handlers<\/b><\/h3>\n<p><span style=\"font-size: small\">Adding event handlers is one of the important tasks. These event handlers are required to start capturing an audio, stop capturing the audio, and then play back the captured audio. <\/span><\/p>\n<p><span style=\"font-size: small\">To add the event handlers:<\/span><\/p>\n<ol>\n<li>\n<p><span style=\"font-size: small\">Open the MainPage.xaml.vb page, and add the following code: <\/span><\/p>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.27%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 67px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\"><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> System.IO<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> System.Threading<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> System.Windows<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> System.Windows.Media.Imaging<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> System.Windows.Threading<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> Microsoft.Phone.Controls<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> Microsoft.Phone.Shell<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> Microsoft.Xna.Framework<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Imports<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> Microsoft.Xna.Framework.Audio<\/span>  <\/p><\/pre>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\">To simulate the XNA Framework, add the following code to the constructor of your MainPage class: <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.36%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 76px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\"><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: green;font-size: 8.5pt\">' Timer to simulate the XNA Framework game loop (Microphone is from the XNA Framework).<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: green;font-size: 8.5pt\"><span>&nbsp;<\/span><\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Dim<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> dt <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">New<\/span> <span style=\"color: #2b91af\">DispatcherTimer<\/span>()<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">dt.Interval = <span style=\"color: #2b91af\">TimeSpan<\/span>.FromMilliseconds(33)<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">AddHandler<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> dt.Tick, <span style=\"color: blue\">AddressOf<\/span> dt_Tick<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">dt.Start()<\/span> <\/p><\/pre>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\">To create a new Microphone.BufferReady event handler, add the following code: <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.26%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 26px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\"><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">AddHandler<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> microphone.BufferReady, <span style=\"color: blue\">AddressOf<\/span> microphone_BufferReady<\/span><\/p><\/pre>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\">After adding all the code mentioned in the previous steps, your constructor should look like the following: <\/span><\/p>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.36%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 76px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\"><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: green;font-size: 8.5pt\">''' Constructor <\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Public<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span> <span style=\"color: blue\">New<\/span>()<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>InitializeComponent()<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: green\">' Timer to simulate the XNA Framework game loop (Microphone is from the XNA Framework).<\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Dim<\/span> dt <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">New<\/span> <span style=\"color: #2b91af\">DispatcherTimer<\/span>()<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>dt.Interval = <span style=\"color: #2b91af\">TimeSpan<\/span>.FromMilliseconds(33)<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">AddHandler<\/span> dt.Tick, <span style=\"color: blue\">AddressOf<\/span> dt_Tick<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>dt.Start()<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">AddHandler<\/span> microphone.BufferReady, <span style=\"color: blue\">AddressOf<\/span> microphone_BufferReady<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span>  <\/p><\/pre>\n<\/div>\n<\/div>\n<\/li>\n<li><span style=\"font-size: small\">To implement the BufferReady event handler, add the following code: <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.4%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 95px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\"><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Private<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span> microphone_BufferReady(<span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> <span style=\"color: #2b91af\">EventArgs<\/span>)<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>microphone.GetData(buffer)<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>stream.Write(buffer, 0, buffer.Length)<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span>  <\/p><\/pre>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\"><i>Note: While recording, this method copies the data from the microphone to a buffer. Later, it copies that buffer<\/i><i> to a stream so that the audio can be played back again.<\/i> <\/p>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">Add the following code to create an event handler for the record button. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.44%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 82px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Private<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span> recordButton_Click(<span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> <span style=\"color: #2b91af\">EventArgs<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span><span style=\"color: green\">&#8216; Get audio data in 1 second chunks<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span>microphone.BufferDuration = <span style=\"color: #2b91af\">TimeSpan<\/span>.FromMilliseconds(1000)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span><span style=\"color: green\">&#8216; Allocate memory to hold the audio data<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;<\/span>buffer = <span style=\"color: blue\">New<\/span> <span style=\"color: blue\">Byte<\/span>(microphone.GetSampleSizeInBytes(microphone.BufferDuration) &#8211; 1) {}<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span><span style=\"color: green\">&#8216; Set the stream back to zero in case there is already something in it<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span>stream.SetLength(0)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span><span style=\"color: green\">&#8216; Start recording<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span>microphone.Start()<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 8.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Consolas;font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\">SetButtonStates(<span style=\"color: blue\">False<\/span>, <span style=\"color: blue\">False<\/span>, <span style=\"color: blue\">True<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp; <\/span><span>&nbsp;&nbsp;<\/span>UserHelp.Text = <span style=\"color: #a31515\">&#8220;record&#8221;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span>StatusImage.Source = microphoneImage<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span><\/p>\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">  <\/pre>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\"><i>Note: This method will start capturing the audio. It also allocates memory to hold the audio for 1 second<\/i>.<i>&nbsp;<\/i> <\/p>\n<p><\/span><\/li>\n<li><span style=\"font-size: small\">Add the following code to create an event handler for the stop button. This method will stop capturing the audio.&nbsp;\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.35%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 108px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Private<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span> stopButton_Click(<span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> <span style=\"color: #2b91af\">EventArgs<\/span>)<\/span><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">If<\/span> microphone.State = <span style=\"color: #2b91af\">MicrophoneState<\/span>.Started <span style=\"color: blue\">Then<\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: green\">' In RECORD mode, user clicked the <\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: green\">' stop button to end recording<\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>microphone.Stop()<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp; <\/span><span>&nbsp;<\/span><span style=\"color: blue\">ElseIf<\/span> soundInstance.State = <span style=\"color: #2b91af\">SoundState<\/span>.Playing <span style=\"color: blue\">Then<\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;<\/span><span>&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: green\">' In PLAY mode, user clicked the <\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: green\">' stop button to end playing back<\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>soundInstance.Stop()<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">End<\/span> <span style=\"color: blue\">If<\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SetButtonStates(<span style=\"color: blue\">True<\/span>, <span style=\"color: blue\">True<\/span>, <span style=\"color: blue\">False<\/span>)<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>UserHelp.Text = <span style=\"color: #a31515\">\"ready\"<\/span><\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>StatusImage.Source = blankImage<\/span><\/p><p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span><\/p><\/pre>\n<\/div>\n<\/div>\n<p><\/span>&nbsp; <\/li>\n<li><span style=\"font-size: small\">Add the following code to create an event handler for the play button. <\/span>\n<div id=\"codeSnippetWrapper\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;margin: 20px 0px 10px;width: 95.18%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 83px;max-height: 200px;font-size: 8pt;overflow: auto;cursor: text;border: silver 1px solid;padding: 4px\">\n<div id=\"codeSnippet\" style=\"text-align: left;line-height: 12pt;background-color: #f4f4f4;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;height: 22px;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">Private<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span> playButton_Click(<span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> <span style=\"color: #2b91af\">EventArgs<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">If<\/span> stream.Length &gt; 0 <span style=\"color: blue\">Then<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: green\">&#8216; Update the UI to reflect that<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: green\">&#8216; sound is playing<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SetButtonStates(<span style=\"color: blue\">False<\/span>, <span style=\"color: blue\">False<\/span>, <span style=\"color: blue\">True<\/span>)<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>UserHelp.Text = <span style=\"color: #a31515\">&#8220;play&#8221;<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>StatusImage.Source = speakerImage<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: green\">&#8216; Play the audio in a new thread so the UI can update.<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">Dim<\/span> soundThread <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">New<\/span> <span style=\"color: #2b91af\">Thread<\/span>(<span style=\"color: blue\">New<\/span> <span style=\"color: #2b91af\">ThreadStart<\/span>(<span style=\"color: blue\">AddressOf<\/span> playSound))<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>soundThread.Start()<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';font-size: 8.5pt\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: blue\">End<\/span> <span style=\"color: blue\">If<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';color: blue;font-size: 8.5pt\">End<\/span><span style=\"font-family: 'Courier New';font-size: 8.5pt\"> <span style=\"color: blue\">Sub<\/span><\/span><\/p>\n<pre style=\"text-align: left;line-height: 12pt;background-color: white;margin: 0em;width: 100%;font-family: 'Courier New', courier, monospace;direction: ltr;color: black;font-size: 8pt;overflow: visible;border-style: none;padding: 0px\">  <\/pre>\n<\/div>\n<\/div>\n<p><span style=\"font-size: small\"><i>Note: This method will allocate a new SoundEffect object and play back the captured audio.<\/i><i>&nbsp;<\/i> <\/span><\/li>\n<\/ol>\n<p><span style=\"font-size: small\">Voila! Now your microphone for Windows Phone 7 is ready! You just need to build and debug the application.<\/span><\/p>\n<h3><b>Step 3 &#8211;<\/b><b> <\/b><b>Build and debug the application<\/b><\/h3>\n<ol>\n<li><span style=\"font-size: small\">To build the application, select Build &gt; Build Solution. The project should build without any errors. <\/span><\/li>\n<li><span style=\"font-size: small\">To debug the application, set the deployment target of the application to &ldquo;Windows Phone 7 Emulator&rdquo;.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0223.png\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/4341.Debug_.gif\" border=\"0\" \/> <\/li>\n<li><span style=\"font-size: small\">Select Debug &gt; Start Debugging. The emulator window is displayed.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0243.jpg\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/3247.Emulator.bmp\" width=\"265\" border=\"0\" height=\"564\" \/> <\/li>\n<li><span style=\"font-size: small\">To start recording the audio, click the Record button.<s><\/s>&nbsp;<br \/><\/span><s><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0253.png\"><\/a><\/s><s><\/s><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/4276.Record.bmp\" border=\"0\" \/> <\/li>\n<li><span style=\"font-size: small\">To stop recording the audio, click the Stop button.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0263.png\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/0246.Stop_.bmp\" border=\"0\" \/> <\/li>\n<li><span style=\"font-size: small\">To play back the captured audio, click the Play button.&nbsp;<br \/><\/span><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0273.png\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/4503.Play_.bmp\" border=\"0\" \/>&nbsp;<\/li>\n<\/ol>\n<p><i><span style=\"font-size: small\">Note: To stop debugging the application, select Debug &gt; Stop Debugging.<\/span><\/i><\/p>\n<p><span style=\"font-size: small\">Finally, your microphone application for Windows Phone 7 is ready to be published into the marketplace. Now, you just need to rebuild your application for the release. <\/span><\/p>\n<h3><b>Step 4 &#8211;<\/b><b> <\/b><b>Rebuild in the release mode before publishing<\/b><\/h3>\n<ol>\n<li><span style=\"font-size: small\">On the standard toolbar, change the configuration manager to Release<\/span>.&nbsp;<br \/><a href=\"http:\/\/blogs.msdn.com\/controlpanel\/blogs\/posteditor.aspx\/$clip_image0283.png\"><\/a><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/02\/3426.Release.bmp\" border=\"0\" \/> <\/li>\n<li><span style=\"font-size: small\">To rebuild the application, select Build &gt; Rebuild. The XAP file of the application is generated. <\/span><\/li>\n<\/ol>\n<p><span style=\"font-size: small\">To submit your application to the market place, you can refer to<strong> <\/strong><\/span><a href=\"http:\/\/create.msdn.com\/en-US\/home\/about\/app_submission_walkthrough_upload\"><span style=\"font-size: small\">upload your application walkthrough<\/span><\/a><span style=\"font-size: small\">.<\/span><\/p>\n<h3><b>Summary<\/b><\/h3>\n<p><span style=\"font-size: small\">That&rsquo;s it! We&rsquo;ve now seen that creating a microphone application for Windows Phone 7 isn&rsquo;t that tough. In fact, you&rsquo;ve created it in just 4 simple steps! <\/span><\/p>\n<p><span style=\"font-size: small\">You can find the full source code for the Visual Basic Silverlight Microphone application <\/span><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff431744(v=VS.92).aspx\"><span style=\"font-size: small\">here<\/span><\/a><span style=\"font-size: small\">. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last post, I explained how to create a mini browser for Windows Phone 7. In this blog, I want to share a sample that will help you to create a microphone application for Windows Phone 7. This application will have the feature to capture audio from a microphone and then play back the [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[195],"tags":[137,167,180],"class_list":["post-703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-basic","tag-silverlight","tag-vb2010","tag-windows-phone"],"acf":[],"blog_post_summary":"<p>In our last post, I explained how to create a mini browser for Windows Phone 7. In this blog, I want to share a sample that will help you to create a microphone application for Windows Phone 7. This application will have the feature to capture audio from a microphone and then play back the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=703"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/703\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}