ISpLexicon::AddPronunciation (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

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] A pointer to memory that contains the null-terminated word to add. The length, which includes the terminating null character, must be less than or equal to SP_MAX_WORD_LENGTH.
LangID
[in] The language ID of the word pointed to by the pszWord parameter. The speech user default will be used if LANGID is omitted.
ePartOfSpeech
[in] The part of speech as a value of the SPPARTOFSPEECH enumerated type.
pszPronunciation
[in] A pointer to memory that contains the null-terminated pronunciation of the word in phoneme IDs (not phone labels). Multiple pronunciations may be added for a single word. The length must be less than or equal to SP_MAX_PRON_LENGTH.  pszPronunciation can be NULL.

Return values

Value Description
S_OK Function completed successfully.
E_INVALIDARG At least one of the parameters is not valid.
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.

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.
}