Enabling TTS

You enable TTS for your application to provide verbal feedback to your users about your application.

    To enable TTS

  1. Get the speech interface using IfmManage::get_Speech.
  2. Call the IAPCSpeech::Speak or IAPCSpeech::SpeakEx function to speak a sentence.
  3. Create a sink to handle TTS messages.

    Note If you use IAPCSpeech::SpeakEx and want to do text normalization (changing word pronunciation based on context), call IAPCSpeech::CreateSpkContext.

  4. If you want to use the voice text interfaces, call IAPCSpeech::QuerySpeechInterface to get the IVTxtAttributes and IVoiceText interfaces. The following table shows these interfaces.
Interface
Description
IVTxtAttributes Controls the attributes of a voice text object
IVoiceText Registers an application to use a voice text object and controls playback of text

The code examples used in this section are part of a complete sample application, TTS.dsp, included in the SDK. TTS.dsp shows a TTS application that reads the user-selected information from the menu.

The following code example shows how the Read Menu command is implemented.

VOID CTTSApp::ProcessMessage(LONG uMsg, LONG wParam, LONG lParam)
{
    long lCurSel = 0;
    long lCount = 0;
    long lId = 0;
    int i;
    BSTR bstr;
    IASPowerListBoxItem *pItem = NULL;
    long lItemData = NULL;

    if(uMsg == WM_COMMAND && LOWORD(wParam) == IDC_LISTBOX &&
        HIWORD(wParam) == LBN_DBLCLK) // Some menu option is
                                      // selected
    {
        switch (HIWORD(lParam)) // Identifier of the item that
                                // is selected
// in HIWORD(lParam)
        {
        // When the user selects the Read Menu command the application
        // passes each command and its identifier to the Speak
        // function. When the Speak function is about to say each
        // command, it initiates a VTXTF_SPEAK message with the bookmark
        // identifier in the lParam.

        case IDM_READMENU:
            m_pListBox->get_Count(&lCount);
            for(i=0; i<lCount; i++)
            {
                m_pListBox->ItemAt(i, (IDispatch **)&pItem);
                pItem->get_Caption(&bstr);
                pItem->get_ItemId(&lId);
                m_pSpeech->Speak(bstr, lId);
            }
            break;

        // When the Exit command is selected, a flag is set so that
        // the application can exit after the VTXTF_SPEAKDONE message 
        // is received.

        case IDM_EXIT:
            m_bExiting = TRUE;
:
        default:
            break;
        } // end switch
    } //end if command
}

The following code example shows how the TTS notification sink is handled.

STDMETHODIMP 
CAppMessageSink::HandleMessage(IDispatch* pdispControl, LONG uMsg, LONG wParam, LONG lParam)
{
    switch(uMsg)
    {
    default:
        break;

    case WM_SPCH_NOTIFY:    // Notifications from TTS engine
        switch(wParam)
        {
        default:
            break;

        case VTXTF_SPEAKDONE:    // When a TTS phrase is done, this is called
            g_pApp->OnSpeakDone();    // Call a CTTSApp function to handle this
            break;
            
        case VTXTF_SPEAK:    // Messages fired while TTS engine is speaking, holds 
                            // the bookmark identifier passed to the Speak function
            g_pApp->SetFocusOnId(lParam);    // in this App, the bookmark identifier is the 
            break;                            // Identifier of the menu item about to be spoken
        } //end switch(wParam)
        break;

    case WM_SETTINGCHANGE:        // Fired when a system setting changed
        if(wParam == SPI_SETAPCFEEDBACK) g_pApp->GetFeedbackLevels();    // Feedback level changed
        break;                                                            // Refresh our applications variables

    } //end switch(uMsg)

    return S_FALSE; // return S_FALSE to keep message processing down the hierarchy
}