SpeechRecognizerUx.SpeechRecognizerUx() constructor
The SpeechRecognizerUx() constructor initializes a new instance of the SpeechRecognizerUx class.
Syntax
public SpeechRecognizerUx()
<sp:SpeechRecognizerUx />
<div data-win-control="BingWinJS.SpeechRecognizerUx" />
Remarks
In most cases, you should create the SpeechRecognizerUx directly in markup, as shown in the syntax section. However, if you wish to dynamically add the control, you can do so by creating the control in code and then adding it to an existing container on the page.
Example
The following code example creates a SpeechRecognizer instance, creates a SpeechRecognizerUx, binds them together, and adds the control to a UI container element named SpeechHostPanel.
using Microsoft.Bing.Speech;
using Microsoft.Bing.Speech.Xaml;
...
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
SpeechRecognizer SR;
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// Apply credentials from the Windows Azure Data Marketplace.
var credentials = new SpeechAuthorizationParameters();
credentials.ClientId = "<YOUR CLIENT ID>";
credentials.ClientSecret = "<YOUR CLIENT SECRET>";
// Initialize the speech recognizer.
SR = new SpeechRecognizer("en-US", credentials);
// Create a SpeechRecognizerUx control and bind it to
// the speech recognizer.
var SpeechControl = new.SpeechRecognizerUx();
SpeechControl.SpeechRecognizer = SR;
// Add the control to the page.
SpeechHostPanel.Children.Add(SpeechControl);
}
var SR;
function pageLoaded() {
// Apply credentials from the Windows Azure Data Marketplace.
var credentials = new Bing.Speech.SpeechAuthorizationParameters();
credentials.clientId = "YOUR CLIENT ID";
credentials.clientSecret = "YOUR CLIENT SECRET";
// Initialize the speech recognizer.
SR = new Bing.Speech.SpeechRecognizer("en-US", credentials);
// Create a speech control.
speechControl = document.createElement("div");
speechControl.setAttribute("id", "SpeechControl");
speechControl.setAttribute("data-win-control", "BingWinJS.SpeechRecognizerUx");
// Place it on the page.
document.getElementById("SpeechHostPanel ").appendChild(speechControl);
// Activate it in WinJS
WinJS.UI.process(speechControl);
}
function speakButton_Click(sender, e) {
// Bind the control to the SpeechRecognizer locally
// before calling RecognizeSpeechToTextAsync.
document.getElementById("SpeechControl").winControl.speechRecognizer = SR;
...
}
Javascript developers dynamically adding the SpeechRecognizerUx control to a page must call the WinJS.UI.process function on the control before binding it to the SpeechRecognizer.
Requirements
Minimum Supported Client |
Windows 8 |
Required Extensions |
Bing.Speech |
Namespace |