Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Microsoft Speech Platform

Helper Function Examples

An application built on the Speech Platform needs to find tokens and instantiate objects that meet certain criteria from the resources available on a computer. Helper functions, distributed in the sphelper.h file, are the recommended way for applications to interact with tokens and categories whenever possible. The following table lists, describes, and provides examples of commonly used helper functions for working with tokens and categories.

Helper Function | ActionExample Helper Function Call
SpGetDefaultTokenFromCategoryID
CComPtr<ISpObjectToken> m_cpEngineToken;
hr = SpGetDefaultTokenFromCategoryId
(SPCAT_RECOGNIZERS, &m_cpEngineToken);
Creates the default token from a CategoryID. The last argument tells the Speech Platform to create the token if it does not currently exist.
SpFindBestToken
CComPtr<ISpObjectToken> cpTokenEng;
hr = SpFindBestToken(SPCAT_RECOGNIZERS,
  L"Language=409", L"VendorPreferred", 
&cpTokenEng);
Finds the most appropriate token given a set of required and optional criteria. For details on attribute matching see Enumerate and Inspect Tokens.
SpEnumTokens
CComPtr<IEnumSpObjectTokens> cpIEnum;
hr = SpEnumTokens(SPCAT_VOICES, 
L"Gender=Female;Language=409", 
L"Age=Child", &cpIEnum);
Returns a token enumerator containing all tokens meeting a set of required and optional attributes. Tokens in the enumerator are sorted in the order specified in Enumerate and Inspect Tokens.
SpCreateDefaultObjectFromCategoryID
CComPtr<ISpVoice> cpVoice; 
SpCreateDefaultObjectFromCategoryID
(SPCAT_VOICES, &cpVoice);
Creates the default object in a category, such as a Voice or Recognizer

Table 1. Helper functions for tokens and categories

See Helper Functions for a complete listing of helper functions provided by the Speech Platform.