Text2Speech.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Text2Speech.h : CText2Speech 的声明
  2. /*************************************************************
  3. /* Copyright (C), 2010-2020, ***. Co., Ltd.
  4. /* 文件名: Text2Speech.h
  5. /* 作者: Jeff.W
  6. /* 创建日期: 2010-08-07
  7. /* 版本号: Ver 1.0.0.0
  8. /* 描述: 文本转语音;
  9. /* 其它:
  10. /* :
  11. /*
  12. /* 历史修改记录:
  13. /* 作者 时间 版本 描述
  14. /* Jeff.W 10/08/07 1.0.0.0 创建这个模块;
  15. /* Jeff.W 14/12/20 1.0.0.1 修改成可在UNICODE和多字节下使用;
  16. ***************************************************************/
  17. #ifndef __TEXT_2_SPEECK_HEADER__
  18. #define __TEXT_2_SPEECK_HEADER__
  19. #include <atlbase.h>
  20. extern CComModule _Module;
  21. #include <atlcom.h>
  22. #include "sapi.h"
  23. #include "sphelper.h"
  24. #include "spuihelp.h"
  25. // Speech SDK支持事件。
  26. // 为了与窗口交互,这里在类中定义了消息WM_TTSEVENT。
  27. // 当发生Speech事件时,向相应的窗口发送WM_TTSEVENT消息。在窗口中响应该消息就响应了相应的事件。
  28. // speech message
  29. #define WM_TTSEVENT WM_USER + 101
  30. #define USE_CSTRING 0
  31. #if 0
  32. typedef struct __STVOICES
  33. {
  34. ULONG uVoiceIndex; // 语音在系统中的索引位置;
  35. WCHAR szDescription; // 语音在系统中的名称描述;
  36. }STVoices,*pSTVoices;
  37. #endif
  38. #pragma once
  39. class CText2Speech
  40. {
  41. public:
  42. CText2Speech(void);
  43. virtual ~CText2Speech(void);
  44. // 初始化和释放函数;
  45. BOOL Initialize(IN HWND hWnd = NULL);
  46. void Destroy();
  47. // 语音操作函数;
  48. HRESULT Speak(IN const TCHAR *pText, IN DWORD dwFlags = SPF_DEFAULT);
  49. HRESULT Pause(){ return m_cpVoice->Pause(); }
  50. HRESULT Resume(){ return m_cpVoice->Resume(); }
  51. // 语速函数;
  52. HRESULT SetRate(IN long lRateAdjust){ return m_cpVoice->SetRate(lRateAdjust); }
  53. HRESULT GetRate(OUT long* plRateAdjust){ return m_cpVoice->GetRate(plRateAdjust); }
  54. // 音量函数;
  55. HRESULT SetVolume(IN USHORT usVolume){ return m_cpVoice->SetVolume(usVolume); }
  56. HRESULT GetVolume(OUT USHORT* pusVolume){ return m_cpVoice->GetVolume(pusVolume); }
  57. // 语言函数;
  58. ULONG GetVoiceCount();
  59. HRESULT GetVoice(OUT WCHAR **ppszDescription, IN ULONG lIndex = -1);
  60. HRESULT SetVoice(IN WCHAR **ppszDescription);
  61. HRESULT SetVoice(IN const ULONG &uIndex);
  62. // 获取/设置输出频率
  63. HRESULT GetOutAudio(OUT SPSTREAMFORMAT &eFmt);
  64. HRESULT SetOutAudio(IN const SPSTREAMFORMAT &eFmt = SPSF_8kHz8BitMono);
  65. // 播放WAV文件;
  66. HRESULT PlayWav(IN const TCHAR *szWavFileName);
  67. // 将文本保存在WAV文件中;
  68. HRESULT Save2Wav(IN const TCHAR *pText, IN const TCHAR *szWavFileName);
  69. #if USE_CSTRING
  70. // 获取错误信息函数;
  71. CString GetErrorString() {
  72. return m_sError;
  73. }
  74. #endif
  75. // interface
  76. CComPtr<ISpVoice> m_cpVoice; // 语音接口;
  77. CComPtr<ISpAudio> m_cpOutAudio; // 声音输出接口;
  78. private:
  79. #if USE_CSTRING
  80. CString m_sError;
  81. #endif
  82. };
  83. #endif