GrammarBuilder.Culture Property


Gets or sets the culture of the speech recognition grammar.

Namespace:   System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)

public CultureInfo Culture { get; set; }

Property Value

Type: System.Globalization.CultureInfo

The culture of the GrammarBuilder. The default is the executing thread's CurrentUICulture property.

The Grammar constructor creates a Grammar object that can be used by a speech recognizer of the corresponding culture. Only the Culture property of the GrammarBuilder that is provided as the parameter to the Grammar constructor is used to set the culture of the resulting speech recognition grammar.

Microsoft Windows and the System.Speech API accept all valid language-country codes. To perform speech recognition using the language specified in the Culture property, a speech recognition engine that supports that language-country code must be installed. The speech recognition engines that shipped with Microsoft Windows 7 work with the following language-country codes.

  • en-GB. English (United Kingdom)

  • en-US. English (United States)

  • de-DE. German (Germany)

  • es-ES. Spanish (Spain)

  • fr-FR. French (France)

  • ja-JP. Japanese (Japan)

  • zh-CN. Chinese (China)

  • zh-TW. Chinese (Taiwan)

Two-letter language codes such as "en", "fr", or "es" are also permitted.

The following example creates a speech recognition grammar for ordering a pizza with up to four toppings. It specifically sets the GrammarBuilder object's culture to English (United States).

private static Grammar CreatePizzaGrammar()

  // Create a Choices object with alternatives for toppings.
  Choices toppings = new Choices(new string[] {
    "cheese", "mushroom", "tomato", "onion",
    "anchovy", "chicken", "pepperoni"});

  // Create a GrammarBuilder and append the Choices object.
  GrammarBuilder andToppings = new GrammarBuilder("and", 0, 1);

  // Construct the phrase.
  GrammarBuilder gb = new GrammarBuilder("I would like a", 0, 1);
  gb.Append(new GrammarBuilder(andToppings, 0, 3));

  // Create the Grammar from the GrammarBuilder.
  Grammar grammar = new Grammar(gb);
  grammar.Name = "Pizza Order";

  return grammar;

.NET Framework
Available since 3.0
Return to top