Skip to content

Add language slugs (System.Speech) #11221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ Console.WriteLine("Root Rule " + bookFlight.Root.Id);
Grammar g = new Grammar(bookFlight);
g.Name = ("City Chooser");
recognizer.LoadGrammarAsync(g);

```

]]></format>
Expand Down
9 changes: 3 additions & 6 deletions xml/System.Speech.Recognition.SrgsGrammar/SrgsOneOf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@
## Examples
The following example uses the <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> element to build lists of <xref:System.Speech.Recognition.SrgsGrammar.SrgsItem> elements containing country/region names, any one of which may be used to recognize the containing phrase. The example then adds one of the resulting <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> objects to their respective rules for European and South American countries/regions. Further on, the example uses the <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> object to group rule references to `ruleEurope` and `ruleSAmerica` into a list of two alternatives, either one of which may be used to recognize spoken input.

```
```csharp
public void WorldSoccerWinners ()
{

// Create an SrgsDocument, create a new rule
// and set its scope to public.
SrgsDocument document = new SrgsDocument();
Expand Down Expand Up @@ -121,7 +120,6 @@ public void WorldSoccerWinners ()
document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
document.Root = winnerRule;
}

```

]]></format>
Expand Down Expand Up @@ -236,7 +234,7 @@ public void WorldSoccerWinners ()
## Examples
The following example creates a grammar that recognizes the phrase "A nation that has won the World Cup is" followed by the name of a country/region that has won the World Cup. The example uses the <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> element to build lists of acceptable country/region names from an array of <xref:System.String> objects. The example then adds one of the resulting <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> objects to their respective rules for European and South American countries/regions.

```
```csharp
public void WorldSoccerWinners ()
{
// Create a grammar from an SRGSDocument, create a new rule
Expand Down Expand Up @@ -305,10 +303,9 @@ public void WorldSoccerWinners ()
## Examples
The following example creates a grammar that recognizes the phrase "A nation that has won the World Cup is" followed by the name of a country/region that has won the World Cup. The example uses the <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> object to build lists of acceptable country/region names from an array of <xref:System.Speech.Recognition.SrgsGrammar.SrgsItem> objects. Using the <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf.Add%2A> method, the example appends an <xref:System.Speech.Recognition.SrgsGrammar.SrgsItem> that contains the string "Italy" to the <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> object `oneOfEurope`.

```
```csharp
public void WorldSoccerWinners ()
{

// Create an SrgsDocument, create a new rule
// and set its scope to public.
SrgsDocument document = new SrgsDocument();
Expand Down
8 changes: 4 additions & 4 deletions xml/System.Speech.Recognition.SrgsGrammar/SrgsRuleRef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
## Examples
The following example creates a grammar that recognizes the phrase "A nation that has won the World Cup is" followed by the name of a country that has won the World Cup. After creating the <xref:System.Speech.Recognition.SrgsGrammar.SrgsRule> object `winnerRule` and giving it the string identifier `WorldCupWinner`, the example appends the string "A nation that has won the World Cup is" to the rule. Using <xref:System.Speech.Recognition.SrgsGrammar.SrgsOneOf> objects, the example then builds a list of European countries/regions and a list of South American countries/regions, and adds each list to its respective rule, `ruleEurope` or `ruleSAmerica`. The example then creates rule references for `ruleEurope` and `ruleSAmerica` and adds them to the `WorldCupWinner` rule.

```
```csharp
public void WorldSoccerWinners ()
{

Expand Down Expand Up @@ -141,7 +141,7 @@ public void WorldSoccerWinners ()

The created grammar has the following form.

```
```xml
<grammar version="1.0" xml:lang="en-US" xmlns="http://www.w3.org/2001/06/grammar" root="WorldCupWinner">
<rule id="WorldCupWinner" scope="public">
<item> A nation that has won the world cup is </item>
Expand Down Expand Up @@ -218,7 +218,7 @@ public void WorldSoccerWinners ()

The second method, `CreateGrammarForRoute`, creates an <xref:System.Speech.Recognition.SrgsGrammar.SrgsDocument> element named `grammar` with a rule reference specified by the `Uri` passed to it by `GrammarUrlForRoute`. Note that the variable named _route is a member of an enclosing class.

```
```csharp
private Uri GrammarUrlForRoute(string route)
{
return new Uri("http://localhost/MyBus/MyBusLocations.grxml#LocationsForRoute" + route);
Expand Down Expand Up @@ -292,7 +292,7 @@ private SrgsDocument CreateGrammarForRoute()
## Examples
The following example creates a grammar for choosing the cities for a flight. The example constructs two <xref:System.Speech.Recognition.SrgsGrammar.SrgsRuleRef> instances, each of which specifies a semantic key. Both rule references target the same <xref:System.Speech.Recognition.SrgsGrammar.SrgsRule> object, named `cities`, but tag the recognition result from the rule reference with a different semantic key. The semantic key identifies a recognized city as the departure city or the arrival city for the flight. The handler for the <xref:System.Speech.Recognition.SpeechRecognitionEngine.SpeechRecognized> event uses the keys to retrieve the semantics values created using <xref:System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag.%23ctor%2A> from the recognition result.

```
```csharp
using System;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,20 @@
## Remarks
The default semantic format for System.Speech conforms to the W3C [Semantic Interpretation for Speech Recognition (SISR) Version 1.0](https://www.w3.org/TR/semantic-interpretation/), where the format for `tag` elements that contain script is `semantics/1.0`. You must specify the script for <xref:System.Speech.Recognition.SrgsGrammar.SrgsSemanticInterpretationTag> objects using this format. In the syntax of `semantics/1.0`:

- The Rule Variable of the containing rule element is identified by "out".

- The name of the object that has access to the Rule Variable of rule elements outside the containing rule element is identified by "rules".

- The result from the latest referenced rule that matches the utterance can be represented by "rules.latest()".
- The Rule Variable of the containing rule element is identified by "out".
- The name of the object that has access to the Rule Variable of rule elements outside the containing rule element is identified by "rules".
- The result from the latest referenced rule that matches the utterance can be represented by "rules.latest()".

You can also associate a semantic value with a phrase in a grammar without using script, using the <xref:System.Speech.Recognition.SrgsGrammar.SrgsNameValueTag> object.



## Examples
The following example creates a grammar for choosing the cities for a flight. The example uses <xref:System.Speech.Recognition.SrgsGrammar.SrgsSemanticInterpretationTag> to assign a semantic value to each city, which is the code for the city's airport. The example also uses <xref:System.Speech.Recognition.SrgsGrammar.SrgsSemanticInterpretationTag> to assign a separate semantic key for each of the two references made by the <xref:System.Speech.Recognition.SrgsGrammar.SrgsRuleRef> object named `cityRef` to the <xref:System.Speech.Recognition.SrgsGrammar.SrgsRule> object named `cities`. The semantic keys identify a recognized city as the departure city or the arrival city for the flight. The handler for the <xref:System.Speech.Recognition.SpeechRecognitionEngine.SpeechRecognized> event uses the keys to retrieve the semantics from the recognition result.

In the code example, "out" refers to the Rule Variable of the containing <xref:System.Speech.Recognition.SrgsGrammar.SrgsRule>. The expression "out.LeavingFrom" refers to the property named `LeavingFrom` of the Rule Variable on the rule named `bookFlight`.

The expression "rules.flightCities" refers to the Rule Variable on the rule whose <xref:System.Speech.Recognition.SrgsGrammar.SrgsRule.Id%2A> is `flightCities`, and which is the target of a rule reference. In the example, the expression "out.LeavingFrom=rules.flightCities;" assigns the value from the rule whose <xref:System.Speech.Recognition.SrgsGrammar.SrgsRule.Id%2A> is `flightCities` to the property named `LeavingFrom` of the Rule Variable on the rule named `bookFlight`. See [Semantic Results Content](https://msdn.microsoft.com/library/622291af-615c-4a15-9014-2933aa3f89fe), [Grammar Rule Name Referencing](https://msdn.microsoft.com/library/0777e975-8665-4cc3-957b-752743cb1bb9), and [Grammar Rule Reference Referencing](https://msdn.microsoft.com/library/dec3a809-9aa2-4139-893f-3a549ca1e03e) for more information.

```
```csharp
using System;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
Expand Down Expand Up @@ -136,7 +132,6 @@ namespace SampleRecognition
}
}
}

```

The following is the XML form of the grammar generated by the code in the example above.
Expand Down
3 changes: 1 addition & 2 deletions xml/System.Speech.Recognition.SrgsGrammar/SrgsToken.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
## Examples
The grammar in the following example contains slang words and also has an uncommon word: "whatchamacallit". Adding a custom, inline pronunciation using the <xref:System.Speech.Recognition.SrgsGrammar.SrgsToken.Pronunciation%2A> property of the <xref:System.Speech.Recognition.SrgsGrammar.SrgsToken> class can improve the accuracy of recognition for the word "whatchamacallit" as well as for the entire phrase that contains it. The example uses phones from the Microsoft Universal Phone Set (UPS) to define the custom pronunciations.

```
```csharp
using System;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
Expand Down Expand Up @@ -236,7 +236,6 @@ namespace SampleRecognition
}
}
}

```

]]></format>
Expand Down
2 changes: 0 additions & 2 deletions xml/System.Speech.Recognition/Choices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ public Grammar CreatePhonePhrase()
The following example creates a speech recognition grammar for changing the background color.

```csharp

private Grammar CreateColorChoice()
{

Expand All @@ -569,7 +568,6 @@ private Grammar CreateColorChoice()

return grammar;
}

```

]]></format>
Expand Down
24 changes: 0 additions & 24 deletions xml/System.Speech.Recognition/Grammar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ private static Grammar CreateGrammarFromFile()
citiesGrammar.Name = "SRGS File Cities Grammar";
return citiesGrammar;
}

```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand Down Expand Up @@ -203,7 +201,6 @@ private static Grammar CreateGrammarFromFile()
The following example creates a speech recognition grammar from a local SRGS file (cities.xml) using a file stream. The content of the cities.xml file appears following C# example.

```csharp

// Load a cities grammar from an I/O stream and
// return the new grammar.
private static Grammar CreateGrammarFromStream()
Expand All @@ -217,7 +214,6 @@ private static Grammar CreateGrammarFromStream()
```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand Down Expand Up @@ -393,7 +389,6 @@ private static Grammar CreateSrgsDocumentGrammar()

return citiesGrammar;
}

```

]]></format>
Expand Down Expand Up @@ -469,11 +464,9 @@ private static Grammar CreateGrammarFromFile()
citiesGrammar.Name = "SRGS File Cities Grammar";
return citiesGrammar;
}

```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand Down Expand Up @@ -564,7 +557,6 @@ private static Grammar CreateGrammarFromFile()
The following example loads a local SRGS file (cities.xml) from a file stream and specifies a rule to use as the root of the grammar. The content of the cities.xml file appears in the XML example that follows the C# example.

```csharp

// Load a cities grammar from an I/O stream, use a specific
// rule as the root of the grammar, and return the new grammar.
private static Grammar CreateGrammarFromStream2()
Expand All @@ -577,7 +569,6 @@ private static Grammar CreateGrammarFromStream2()
```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand Down Expand Up @@ -733,7 +724,6 @@ namespace SampleRecognition
}
}
}

```

]]></format>
Expand Down Expand Up @@ -801,7 +791,6 @@ namespace SampleRecognition
The following example loads a local SRGS file (cities.xml) from a file and specifies a rule to use as the root of the grammar. The content of the cities.xml file appears in the XML example that follows the C# example.

```csharp

// Load a cities grammar from a local file, use a specific
// rule as the root of the grammar, and return the new grammar.
private static Grammar CreateGrammarFromFile2()
Expand All @@ -813,7 +802,6 @@ private static Grammar CreateGrammarFromFile2()
```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand Down Expand Up @@ -962,7 +950,6 @@ private static Grammar CreateGrammarFromFile2()
The following example loads a local SRGS file (shuttle.xml) from a file stream. The file contains a relative rule reference to a rule in the cities.xml file, and specifies a base URI to use to resolve the rule reference. The content of the shuttle.xml and cities.xml files appears in the XML examples that follow the C# example.

```csharp

private static Grammar CreateGrammarFromStream3()
{
FileInfo file = new FileInfo(@".\shuttle.xml");
Expand All @@ -974,7 +961,6 @@ private static Grammar CreateGrammarFromStream3()
```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand All @@ -994,7 +980,6 @@ private static Grammar CreateGrammarFromStream3()
```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand Down Expand Up @@ -1133,7 +1118,6 @@ private static Grammar CreateGrammarFromStream3()
The following example creates a speech recognition grammar in an <xref:System.Speech.Recognition.SrgsGrammar.SrgsDocument> that contains a relative rule reference to the cities.xml file, and specifies a URI to use to resolve the rule reference. The content of the cities.xml file appears in the XML example that follows the C# example.

```csharp

private static Grammar CreateSrgsDocumentGrammar3()
{
// Create the SrgsDocument.
Expand Down Expand Up @@ -1163,11 +1147,9 @@ private static Grammar CreateSrgsDocumentGrammar3()

return citiesGrammar;
}

```

```xml

<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar"
Expand Down Expand Up @@ -1396,7 +1378,6 @@ private static Grammar CreateSrgsDocumentGrammar3()
The following example writes information about a <xref:System.Speech.Recognition.Grammar> object to the [console](https://go.microsoft.com/fwlink/?LinkId=159613).

```csharp

private static void DumpGrammarStatus(Grammar item)
{
Console.WriteLine("Grammar name is {0}:", item.Name);
Expand Down Expand Up @@ -1498,7 +1479,6 @@ private static void DumpGrammarStatus(Grammar item)
The following example writes information about a <xref:System.Speech.Recognition.Grammar> object to the [console](https://go.microsoft.com/fwlink/?LinkId=159613).

```csharp

private static void DumpGrammarStatus(Grammar item)
{
Console.WriteLine("Grammar name is {0}:", item.Name);
Expand Down Expand Up @@ -1600,7 +1580,6 @@ private static void DumpGrammarStatus(Grammar item)
The following example creates two <xref:System.Speech.Recognition.Grammar> objects, one for digits and one for fractions. The Grammar objects are assigned names and relative weights and priorities, and loaded by an in-process speech recognizer. The `CreateDigitsGrammar`, `CreateFractionsGrammar`, and `recognizer_SpeechRecognized` methods are not shown here.

```csharp

// Create a Grammar for recognizing numeric digits.
Grammar digitsGrammar = CreateDigitsGrammar();
digitsGrammar.Name = "Digits Grammar";
Expand Down Expand Up @@ -1673,7 +1652,6 @@ recognizer.RecognizeAsync(RecognizeMode.Multiple);
The following example creates two <xref:System.Speech.Recognition.Grammar> objects, one for digits and one for fractions. The <xref:System.Speech.Recognition.Grammar> objects are assigned names and relative weights and priorities, and loaded by an in-process speech recognizer. The `CreateDigitsGrammar`, `CreateFractionsGrammar`, and `recognizer_SpeechRecognized` methods are not shown here.

```csharp

// Create a Grammar for recognizing numeric digits.
Grammar digitsGrammar = CreateDigitsGrammar();
digitsGrammar.Name = "Digits Grammar";
Expand Down Expand Up @@ -1782,7 +1760,6 @@ recognizer.RecognizeAsync(RecognizeMode.Multiple);
The following example writes information about a <xref:System.Speech.Recognition.Grammar> object to the [console](https://go.microsoft.com/fwlink/?LinkId=159613).

```csharp

private static void DumpGrammarStatus(Grammar item)
{
Console.WriteLine("Grammar name is {0}:", item.Name);
Expand Down Expand Up @@ -1963,7 +1940,6 @@ public partial class Form1 : Form
The following example creates two <xref:System.Speech.Recognition.Grammar> objects, one for digits and one for fractions. The <xref:System.Speech.Recognition.Grammar> objects are assigned names and relative weights and priorities, and loaded by an in-process speech recognizer. The `CreateDigitsGrammar`, `CreateFractionsGrammar`, and `recognizer_SpeechRecognized` methods are not shown here.

```csharp

// Create a Grammar for recognizing numeric digits.
Grammar digitsGrammar = CreateDigitsGrammar();
digitsGrammar.Name = "Digits Grammar";
Expand Down
Loading