Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
Microsoft Speech Platform
ISpGrammarBuilder::AddResource
ISpGrammarBuilder::AddResource adds a resource (name and string value) to the grammar rule specified in hRuleState. The resource can be queried by a rule interpreter.
<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT AddResource(</strong> <strong>SPSTATEHANDLE</strong><em> hRuleState</em>, <strong>LPCWSTR</strong> *<em>pszResourceName</em>, <strong>LPCWSTR</strong> *<em>pszResourceValue</em> <strong>);</strong> </pre>
Parameters
- hRuleState
[in] Handle of a state in the rule to which the resource is to be added. - pszResourceName
[in] Address of a null-terminated string specifying the resource name. - pszResourceValue
[in] Address of a null-terminated string specifying the resource value.
Return Values
Value | Description |
---|---|
S_OK | Function completed successfully. |
E_INVALIDARG | At least one of the parameters is invalid. |
SPERR_DUPLICATE_RESOURCE_NAME | The resource already exists. |
E_OUTOFMEMORY | Exceeded available memory. |
FAILED(hr) | Appropriate error message. |
Example
The following code snippet illustrates the use of AddResource.
`
// Declare local identifiers: HRESULT hr = S_OK; CComPtr<ISpGrammarBuilder> cpGrammarBuilder; SPSTATEHANDLE hInit; SPSTATEHANDLE hState;`hr = cpGrammarBuilder->GetRule(L"rule1", 1, 0, TRUE, &hInit;);
if (SUCCEEDED (hr)) { hr = cpGrammarBuilder->CreateNewState(hInit, &hState;); }
if (SUCCEEDED (hr)) { // Call AddResource using the hInitState. hr = cpGrammarBuilder->AddResource(hInit, L"ResName1", L"ResValue1"); }
if (SUCCEEDED(hr)) { // Call AddResource using hState != hInit. hr = cpGrammarBuilder->AddResource(hState, L"ResName2", L"ResValue2"); }
if (SUCCEEDED(hr)) { // Do something here. }