Share via


ISpLexicon::AddPronunciation

Other versions of this page are also available for the following:

Windows Mobile Not SupportedWindows Embedded CE Supported

8/28/2008

This method adds word pronunciations and parts of speech (POS) to the user lexicon. 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 in the pszPronunciation parameter.

Syntax

HRESULT AddPronunciation(
  const WCHAR* pszWord,
  LANGID LangID,
  SPPARTOFSPEECH ePartOfSpeech,
  const SPPHONEID* pszPronunciation
);

Parameters

  • pszWord
    [in] Pointer to the word to add.
  • LangID
    [in] Language identifier 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] Part of speech. Possible values are defined by the SPPARTOFSPEECH enumeration.
  • pszPronunciation
    [in] Pointer to the null-terminated pronunciation of the word in the NUM phone set. Multiple pronunciations can be added for a single word. The length must be equal to or less than SP_MAX_PRON_LENGTH. pszPronunciation can be NULL to indicate no pronunciation.

Return Value

The following table shows the possible return values.

Value Description

S_OK

Function completed successfully.

E_INVALIDARG

At least one of the parameters is invalid or bad.

SP_ALREADY_IN_LEX

The same pronunciation of the word already exists in the user lexicon.

SPERR_APPLEX_READ_ONLY

Cannot add a word to application lexicon.

SPERR_UNINITIALIZED

The interface has not been initialized.

E_OUTOFMEMORY

Exceeded available memory.

FAILED(hr)

Appropriate error message.

Remarks

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

Example

The following is an example of this method.

HRESULT hr;
CComPtr cpLexicon;
hr = cpLexicon.CoCreateInstance(CLSID_SpLexicon);
// 0x409 for English
LANGID langidUS = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
CComPtr cpPhoneConv;
SPPHONEID wszId[SP_MAX_PRON_LENGTH];
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);

Requirements

Header sapi.h, sapi.idl
Library sapilib.lib
Windows Embedded CE Windows CE .NET 4.1 and later

See Also

Reference

ISpLexicon
SAPI Interfaces