📄 texttospeech.h
字号:
// Text2Speech.h: interface for the CText2Speech class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TEXTTOSPEECH_H__7885A537_6324_44E7_9496_C58F79810737__INCLUDED_)
#define AFX_TEXTTOSPEECH_H__7885A537_6324_44E7_9496_C58F79810737__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
///////////////////////////////////////////////////////////////
// active speech engine
//
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include "sapi.h"
#include <sphelper.h>
///////////////////////////////////////////////////////////////
// speech message
//
#define WM_SPEVENT WM_USER+101
///////////////////////////////////////////////////////////////
// text-to-speech class
//
class CASRTextToSpeech
{
public:
CASRTextToSpeech();
virtual ~CASRTextToSpeech();
// initialize
HRESULT Init(HWND hWnd = NULL);
void Close();
// speak
HRESULT Speak(const WCHAR *pwcs, DWORD dwFlags,ULONG *pulStreamNumber=NULL);
HRESULT SpeakText(CString strText, DWORD dwFlags = SPF_ASYNC|SPF_IS_NOT_XML);
HRESULT SpeakXML(CString strXMLText, DWORD dwFlags = SPF_ASYNC|SPF_IS_XML);
HRESULT SpeakTextFile(CString strTextPath);
HRESULT SpeakXMLFile(CString strXMLPath);
HRESULT SpeakFromWAV(CString strPathWAV);
HRESULT SpeakToWAV(CString strText,CString strPathWAV);
HRESULT Pause();
HRESULT Resume();
// rate
HRESULT SetRate(long lRateAdjust);
HRESULT GetRate(long* plRateAdjust);
// volume
HRESULT SetVolume(USHORT usVolume);
HRESULT GetVolume(USHORT* pusVolume);
// voice
ULONG GetVoiceCount();
HRESULT GetVoice(WCHAR **ppszDescription, ULONG lIndex = -1);
HRESULT SetVoice(WCHAR **ppszDescription);
// error string
CString GetLastError()
{
return m_strLastError;
}
void ShowLastError()
{
MessageBox(NULL,m_strLastError,"错误",NULL);
}
// get ComPtr
CComPtr<ISpVoice> GetSpeechVoice()
{
return m_IpVoice;
}
HRESULT SetAudio(SPSTREAMFORMAT eFmt);
private:
// interface
CComPtr<ISpVoice> m_IpVoice;
CComPtr<ISpAudio> m_cpOutAudio;
CString m_strLastError;
};
#endif // !defined(AFX_TEXT2SPEECH_H__7885A537_6324_44E7_9496_C58F79810737__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -