123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- // Text2Speech.h : CText2Speech 的声明
- /*************************************************************
- /* Copyright (C), 2010-2020, ***. Co., Ltd.
- /* 文件名: Text2Speech.h
- /* 作者: Jeff.W
- /* 创建日期: 2010-08-07
- /* 版本号: Ver 1.0.0.0
- /* 描述: 文本转语音;
- /* 其它:
- /* :
- /*
- /* 历史修改记录:
- /* 作者 时间 版本 描述
- /* Jeff.W 10/08/07 1.0.0.0 创建这个模块;
- /* Jeff.W 14/12/20 1.0.0.1 修改成可在UNICODE和多字节下使用;
- ***************************************************************/
- #ifndef __TEXT_2_SPEECK_HEADER__
- #define __TEXT_2_SPEECK_HEADER__
- #include <atlbase.h>
- extern CComModule _Module;
- #include <atlcom.h>
- #include "sapi.h"
- #include "sphelper.h"
- #include "spuihelp.h"
- // Speech SDK支持事件。
- // 为了与窗口交互,这里在类中定义了消息WM_TTSEVENT。
- // 当发生Speech事件时,向相应的窗口发送WM_TTSEVENT消息。在窗口中响应该消息就响应了相应的事件。
- // speech message
- #define WM_TTSEVENT WM_USER + 101
- #define USE_CSTRING 0
- #if 0
- typedef struct __STVOICES
- {
- ULONG uVoiceIndex; // 语音在系统中的索引位置;
- WCHAR szDescription; // 语音在系统中的名称描述;
- }STVoices,*pSTVoices;
- #endif
- #pragma once
- class CText2Speech
- {
- public:
- CText2Speech(void);
- virtual ~CText2Speech(void);
- // 初始化和释放函数;
- BOOL Initialize(IN HWND hWnd = NULL);
- void Destroy();
- // 语音操作函数;
- HRESULT Speak(IN const TCHAR *pText, IN DWORD dwFlags = SPF_DEFAULT);
- HRESULT Pause(){ return m_cpVoice->Pause(); }
- HRESULT Resume(){ return m_cpVoice->Resume(); }
- // 语速函数;
- HRESULT SetRate(IN long lRateAdjust){ return m_cpVoice->SetRate(lRateAdjust); }
- HRESULT GetRate(OUT long* plRateAdjust){ return m_cpVoice->GetRate(plRateAdjust); }
- // 音量函数;
- HRESULT SetVolume(IN USHORT usVolume){ return m_cpVoice->SetVolume(usVolume); }
- HRESULT GetVolume(OUT USHORT* pusVolume){ return m_cpVoice->GetVolume(pusVolume); }
- // 语言函数;
- ULONG GetVoiceCount();
- HRESULT GetVoice(OUT WCHAR **ppszDescription, IN ULONG lIndex = -1);
- HRESULT SetVoice(IN WCHAR **ppszDescription);
- HRESULT SetVoice(IN const ULONG &uIndex);
- // 获取/设置输出频率
- HRESULT GetOutAudio(OUT SPSTREAMFORMAT &eFmt);
- HRESULT SetOutAudio(IN const SPSTREAMFORMAT &eFmt = SPSF_8kHz8BitMono);
- // 播放WAV文件;
- HRESULT PlayWav(IN const TCHAR *szWavFileName);
- // 将文本保存在WAV文件中;
- HRESULT Save2Wav(IN const TCHAR *pText, IN const TCHAR *szWavFileName);
- #if USE_CSTRING
- // 获取错误信息函数;
- CString GetErrorString() {
- return m_sError;
- }
- #endif
- // interface
- CComPtr<ISpVoice> m_cpVoice; // 语音接口;
- CComPtr<ISpAudio> m_cpOutAudio; // 声音输出接口;
- private:
- #if USE_CSTRING
- CString m_sError;
- #endif
- };
- #endif
|