ISpLexicon::AddPronunciation (SAPI 5.4)

Speech API 5.4
Microsoft Speech API 5.4

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

ValueDescription
S_OKFunction completed successfully.
E_INVALIDARGAt least one of the parameters is not valid.
SP_ALREADY_IN_LEXThe same pronunciation of the word already exists in the user lexicon.
SPERR_APPLEX_READ_ONLYCannot add a word to application lexicon.
SPERR_UNINITIALIZEDThe interface has not been initialized.
E_OUTOFMEMORYExceeded 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.
}
Show: