Share via


ISpLexicon::AddPronunciation (SAPI 5.3)

Microsoft Speech API 5.3

ISpLexicon::AddPronunciation

ISpLexicon::AddPronunciation adds word pronunciations and parts of speech (POS) to the user lexicon. .

  
    HRESULT AddPronunciation(
   LPCWSTR          *pszWord,
   LANGID            LangID,
SPPARTOFSPEECH    ePartOfSpeech,
   PCSPPHONEID      *pszPronunciation
);

Parameters

  • pszWord
    [in] The word to add.
  • LangID
    [in] The language ID of the word. The speech user default will be used if LANGID is omitted. Length must be equal to or less than SP_MAX_WORD_LENGTH.
  • ePartOfSpeech
    [in] The part of speech of type SPPARTOFSPEECH.
  • pszPronunciation
    [in] Null-terminated pronunciation of the word in the NUM phone set. Multiple pronunciations may be added for a single word.  The length must be equal to or less than SP_MAX_PRON_LENGTH.  pszPronunciation may be NULL.

Return values

Value
S_OK
E_INVALIDARG
SP_ALREADY_IN_LEX
SPERR_APPLEX_READ_ONLY
SPERR_UNINITIALIZED
E_OUTOFMEMORY
FAILED(hr)

Remarks

See the documentation on ISpPhoneConverter for more information on phone sets.

SAPI will not modify the word if spelling, pronunciation, and POS are the same as an existing entry in the user lexicon. A word can be added without pronunciation by passing in NULL as the pszPronunciation

Example

The following is an example of AddPronunciation.

  
// Declare local identifiers:
HRESULT                      hr = S_OK;
CComPtr<ISpPhoneConverter>   cpPhoneConv;
CComPtr<ISpLexicon>          cpLexicon;
LANGID                       langidUS;
SPPHONEID                    wszId[SP_MAX_PRON_LENGTH];

hr = cpLexicon.CoCreateInstance(CLSID_SpLexicon);

// 0x409 for English.
langidUS = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);

if(SUCCEEDED(hr))
{
   hr = SpCreatePhoneConverter(langidUS, NULL, NULL, &cpPhoneConv;);
}

if(SUCCEEDED(hr))
{
   hr = cpPhoneConv->PhoneToId(L"r eh d", wszId);
}
if(SUCCEEDED(hr))
{
   hr = cpLexicon->AddPronunciation(L"red", langidUS, SPPS_Noun, wszId);
}

if (SUCCEEDED(hr))
{
   // Do stuff here.
}