2009年11月27日 星期五

在 Windows 環境下使用 SAPI 開發語音程式(四):語音合成

之前的文章描述怎麼使用 SAPI 達到語音辨識,相較之下,語音合成
(文字轉語音, TTS )就簡單了許多。

一樣,還是一個 .hpp 和一個 .cpp 檔。


// SpeechSynthesizer.hpp
#ifndef _SPEECHSYNTHESIZER_HPP
#define _SPEECHSYNTHESIZER_HPP

#pragma warning(disable:4995)

#include < sapi.h >
#include < sphelper.h >
#include < string >
#include < cstring >


using namespace std;

class SpeechSynthesizer
{
public:
SpeechSynthesizer();
void initSAPI();
void setSpeakerMike();
void setSpeakerSam();
void setSpeakerMary();
void setVoiceRate(int rate);
void setVoiceVolume(int vol);
void setVoicePitch(int pitch);
void setVoiceOutputWavFile(string filename);
void setVoiceOutputDefault();
void speak(string str);
void readTextFile(string filename);


// protected:
CComPtr < ISpVoice > cpVoice;
int _pitch;
};

#endif

沒有留言: