|
@@ -1,3 +1,4 @@
|
|
|
|
|
+#include "../pch/pch.h"
|
|
|
#include "CSpeech.h"
|
|
#include "CSpeech.h"
|
|
|
|
|
|
|
|
|
|
|
|
@@ -10,3 +11,302 @@ CSpeech::CSpeech()
|
|
|
CSpeech::~CSpeech()
|
|
CSpeech::~CSpeech()
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+void CSpeech::MSSSpeak(LPCTSTR speakContent)// speakContent为LPCTSTR型的字符串,调用此函数即可将文字转为语音
|
|
|
|
|
+{
|
|
|
|
|
+ ISpVoice* pVoice = NULL;
|
|
|
|
|
+
|
|
|
|
|
+ //初始化COM接口
|
|
|
|
|
+
|
|
|
|
|
+ if (FAILED(::CoInitialize(NULL)))
|
|
|
|
|
+ {
|
|
|
|
|
+ MessageBox(NULL, (LPCWSTR)L"COM接口初始化失败!", (LPCWSTR)L"提示", MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取SpVoice接口
|
|
|
|
|
+
|
|
|
|
|
+ HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&pVoice);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (SUCCEEDED(hr))
|
|
|
|
|
+ {
|
|
|
|
|
+ pVoice->SetVolume((USHORT)100); //设置音量,范围是 0 -100
|
|
|
|
|
+ pVoice->SetRate(2); //设置速度,范围是 -10 - 10
|
|
|
|
|
+ hr = pVoice->Speak(speakContent, 0, NULL);
|
|
|
|
|
+
|
|
|
|
|
+ pVoice->Release();
|
|
|
|
|
+
|
|
|
|
|
+ pVoice = NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //释放com资源
|
|
|
|
|
+ ::CoUninitialize();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/*
|
|
|
|
|
+ *如果只是一个0,读不读
|
|
|
|
|
+ **/
|
|
|
|
|
+void CSpeech::SpeakIntXiaoyuWan(int new_num, bool is_after_wan)
|
|
|
|
|
+{
|
|
|
|
|
+ std::wstring path;
|
|
|
|
|
+
|
|
|
|
|
+ if (new_num < 10)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (is_after_wan == true)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (new_num == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\0.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(new_num) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(new_num) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (new_num >= 10 && new_num <= 99)
|
|
|
|
|
+ {
|
|
|
|
|
+ int shi_wei = new_num / 10;
|
|
|
|
|
+ int ge_wei = new_num % 10;
|
|
|
|
|
+
|
|
|
|
|
+ if (is_after_wan == true && (shi_wei > 0 || ge_wei > 0))
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\0.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (shi_wei > 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(shi_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (is_after_wan == true && shi_wei == 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(shi_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\shi.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+
|
|
|
|
|
+ if (ge_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ //如果个位数为0,就不读
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(ge_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (new_num >= 100 && new_num <= 999)
|
|
|
|
|
+ {
|
|
|
|
|
+ int bai_wei = new_num / 100;
|
|
|
|
|
+ int shi_wei = (new_num / 10) % 10;
|
|
|
|
|
+ int ge_wei = new_num % 10;
|
|
|
|
|
+
|
|
|
|
|
+ if (is_after_wan == true && (bai_wei > 0 || shi_wei > 0 || ge_wei > 0))
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\0.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (bai_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(bai_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\hundred.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+
|
|
|
|
|
+ if (shi_wei == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ge_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(shi_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(shi_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (shi_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\shi.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ge_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(ge_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (new_num >= 1000 && new_num <= 9999)
|
|
|
|
|
+ {
|
|
|
|
|
+ int qian_wei = new_num / 1000;
|
|
|
|
|
+
|
|
|
|
|
+ if (qian_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(qian_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\thousand.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+
|
|
|
|
|
+ int bai_wei = (new_num / 100) % 10;
|
|
|
|
|
+ int shi_wei = (new_num / 10) % 10;
|
|
|
|
|
+ int ge_wei = new_num % 10;
|
|
|
|
|
+
|
|
|
|
|
+ if (bai_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(bai_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\hundred.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (shi_wei >= 1 || ge_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(bai_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (shi_wei == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (ge_wei >= 1 && bai_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(shi_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(shi_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (shi_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\shi.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ge_wei >= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\" + to_wstring(ge_wei) + L".wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/*
|
|
|
|
|
+ *读一个整数
|
|
|
|
|
+ **/
|
|
|
|
|
+void CSpeech::SpeakInt(int num)
|
|
|
|
|
+{
|
|
|
|
|
+ wstring path;
|
|
|
|
|
+
|
|
|
|
|
+ if (num > 99999999)
|
|
|
|
|
+ {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (num >= 10000)
|
|
|
|
|
+ {
|
|
|
|
|
+ //大于1万的
|
|
|
|
|
+ int new_num = num / 10000;
|
|
|
|
|
+
|
|
|
|
|
+ CSpeech::SpeakIntXiaoyuWan(new_num);
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\tenthousand.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+
|
|
|
|
|
+ new_num = num % 10000;
|
|
|
|
|
+
|
|
|
|
|
+ CSpeech::SpeakIntXiaoyuWan(new_num, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //小于1万的
|
|
|
|
|
+ CSpeech::SpeakIntXiaoyuWan(num);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/*
|
|
|
|
|
+ *把数字拆解成一个个的读音,调用wav文件播放
|
|
|
|
|
+ *voice_type 1:收款成功 2:退款成功
|
|
|
|
|
+ *num 金额,比如18.23
|
|
|
|
|
+ **/
|
|
|
|
|
+void CSpeech::SpeakNum(int voice_type, std::string num)
|
|
|
|
|
+{
|
|
|
|
|
+ wstring path;
|
|
|
|
|
+
|
|
|
|
|
+ if (voice_type == 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\pay_success.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (voice_type == 2)
|
|
|
|
|
+ {
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\refund_success.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (num.find(".") == std::string::npos)
|
|
|
|
|
+ {
|
|
|
|
|
+ //当整数处理
|
|
|
|
|
+ int n_num = atoi(num.c_str());
|
|
|
|
|
+ if (n_num == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ CSpeech::SpeakInt(n_num);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //当小数处理
|
|
|
|
|
+ double d_num = atof(num.c_str());
|
|
|
|
|
+ if (d_num < 0.00001)
|
|
|
|
|
+ {
|
|
|
|
|
+ //无效的转换
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int n_num = (int)d_num;
|
|
|
|
|
+
|
|
|
|
|
+ CSpeech::SpeakInt(n_num);
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\point.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+
|
|
|
|
|
+ //准备读小数部分
|
|
|
|
|
+ int nPos = num.find(".");
|
|
|
|
|
+ std::string s_xiaoshu = num.substr(nPos + 1);
|
|
|
|
|
+
|
|
|
|
|
+ for (size_t i = 0; i < s_xiaoshu.length(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ int n = atoi(s_xiaoshu.substr(i, 1).c_str());
|
|
|
|
|
+
|
|
|
|
|
+ CSpeech::SpeakInt(n);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ path = CSystem::GetProgramDir() + L"\\music\\yuan.wav";
|
|
|
|
|
+ PlaySound(path.c_str(), NULL, SND_FILENAME | SND_SYNC);
|
|
|
|
|
+}
|