Using text-to-speech in Visual c++6.0

Source: Internet
Author: User
Tags pack sapi

First, the preface

Online many programs can read English and Chinese, the typical is Kingsoft, recently looked, found that the Internet in the VC information is not many, some programs are based on API (such as Vckbase:: Home >> Documentation Center >> online magazine >> Audio technology in the article "Text Speech Conversion Primer" Author: Suyu, plus I benefited a lot in vckbase, now want to return one or two, so I wrote a program based on MFC, hope, please expert advice.

Second, install the TTS engine

To use TTS, Microsoft's TTS engine must be installed, as Suyu has explained, as a user needs to download two files MSTTS.EXE and SPCHAPI.EXE, if you need to read Chinese, you also need to download the Chinese Pronunciation pack Simpchinese Speech Package. These three software can be found on the Microsoft home page, if you publish the program, you need to pack it together. As a programmer, you can download the Microsoft Speech SDK, version 5.1, in the Microsoft home page, and download the Chinese and Japanese language pack SpeechSDK51LangPack.exe.

III. Establishment of program projects

1. Establish an MFC AppWizard (EXE)

2. Choose dialog Based inside the Step1

3. Check the automation option on the STEP2 (this is necessary)

4. End

Iv. Import Type libraries

Find Spai.dll, copy it to your program's res directory (not copy it ^_^), open MFC ClassWizard, select Automation page, click "Add Class ...", select "from a type library ...", select "SA Pi.dll "file, then the system will appear confirm Classes dialog box, asked to import the class, OH, anyway idle is also idle, all selected. To this end, the preparatory work is complete.

V. Sample programs

I wrote a demo program with the following interface:

Click "Speak 中文版" to read the female voice out of "Apple" and click "Speak Chinese" to read the male speaker "apples".

Click "Chinese" and "Chinese" in the following input text box will appear in English and Mandarin, click "read" can be read out, click "Stop" can stop reading. "Rate" means reading speed, "+", "-" Can Change, "Volume" means volume size, "+", "-" can change. "Voice" lists the system's current sound, but, in fact, my computer can only read four kinds, I listed on the right "Mary,mike,sam,chinese", about this, the reason unknown, please enlighten us. Note that, if the input of Chinese, first in the voice to choose the Chinese after the correct voice, reading English should also choose non-Chinese to be able to.

The key code for sound is:

CLSID CLSID_SpVoice;  // class ID for the SAPI SpVoice object
  LPDISPATCH pDisp;    // dispatch interface for the class
  ISpeechVoice voice;   // use the MFC Class Wizard generated wrapper
  CLSIDFromProgID(L"SAPI.SpVoice", &CLSID_SpVoice);
  voice.CreateDispatch(CLSID_SpVoice);
  pDisp = voice.m_lpDispatch;
  HRESULT hr = pDisp->QueryInterface(CLSID_SpVoice, (void**)&voice.m_lpDispatch);
  if (hr == S_OK) {
    pDisp->Release();
  }
  else {
    voice.AttachDispatch(pDisp, TRUE);
  }
  voice.Speak("Hello World", 1);  // asynchronous call to Speak method of ISpeechVoice interface

My program you see the code.

Six, a

I now have a few questions I hope to discuss with you, please do not hesitate to enlighten us.

1. How to adjust intonation. The difference between Mary and Sam is actually a different tone of voice.

2. When reading speech and text synchronization, that is, read which Word to highlight which word.

3. How to transfer TTS on Windows to PocketPC. This problem is my most concerned about, if there is an expert know, the niche is courteous again, must tell me ah, thank you thank you again.

The email:skysoft_z@sina.com of the niche

This article supporting source code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.