ISpLexicon::GetPronunciations (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

ISpLexicon::GetPronunciations

ISpLexicon::GetPronunciations gets pronunciations and parts of speech for a word.

HRESULT GetPronunciations(
   LPCWSTR                  *pszWord,
   LANGID                    LangID,
   DWORD                     dwFlags,
   SPWORDPRONUNCIATIONLIST  *pWordPronunciationList
);

Parameters

pszWord
[in] Pointer to a null-terminated text string as a search keyword. Length must be equal to less than SP_MAX_WORD_LENGTH.
LangID
[in] The language ID of the word. May be zero to indicate that the word can be of any LANGID.
dwFlags
[in] Bitwise flags of type SPLEXICONTYPE indicating that the lexicons searched for this word.
pWordPronunciationList
[in, out] Pointer to SPWORDPRONUNCIATIONLIST structure in which the pronunciations and parts of speech are returned.

Return values

Value Description
S_OK Function completed successfully.
SP_WORD_EXISTS_WITHOUT_PRONUNCIATION The word exists but does not have a pronunciation.
E_POINTER pWordPronunciationList is not a valid write pointer.
E_INVALIDARG At least one of the parameters is invalid or bad.
E_OUTOFMEMORY Exceeded available memory.
SPERR_UNINITIALIZED The interface has not been initialized.
SPERR_NOT_IN_LEX Word is not found in the lexicon.
FAILED(hr) Appropriate error message.

Remarks

The application must create a zero-initialized SPWORDPRONUNCIATIONLIST structure before calling GetPronunciations, using functions such as ZeroMemory or memset to do so. GetPronunciations creates a linked list of word pronunciations that start at the location pointed to by the pvBuffer member of SPWORDPRONUNCIATIONLIST. As long as the SPWORDPRONUNCIATIONLIST structure is still being used, the pvBuffer buffer should not be freed, because GetPronunciations reuses the buffer for reasons of efficiency, and reallocates storage when necessary.

When this structure is no longer needed, free the memory pointed to by pvBuffer by a call to CoTaskMemFree.

Depending on the language, GetPronunciations may return SAPI IDs or Universal Phone Set (UPS) IDs. To determine which phone set (phonetic alphabet) was used to create pronunciations, use the ISpPhoneticAlphabetSelection::IsAlphabetUPS method.

Example

The following example is a code fragment demonstrating the use of GetPronunciations.


// Declare local identifiers:
HRESULT                      hr = S_OK;
CComPtr<ISpLexicon>          cpLexicon;
SPWORDPRONUNCIATIONLIST      *pwordpronlist;
SPWORDPRONUNCIATION          *pwordpron;

memset(pwordpronlist, 0, sizeof(pwordpronlist));

hr = cpLexicon->GetPronunciations(L"resume", 409, eLEXTYPE_USER | eLEXTYPE_APP, pwordpronlist);

if( SUCCEEDED(hr))
{
   for (pwordpron = pwordpronlist->pFirstWordPronunciation;
      pwordpron != NULL;
      pwordpron = pwordpron->pNextWordPronunciation)
      {
         // Do something with the SPWORDPRONUNCIATION structure's
         // members (for example, ePartOfSpeech and szPronunciation).
      }
}

// Free all the buffers.
CoTaskMemFree(pwordpronlist.pvBuffer);