📄 demo_vs2005_c++.cpp
字号:
#include "stdafx.h"
#include <aygshell.h>
#include "resource.h"
#include "ttsapi.h" //in include folder
#include "ttsapi_i.c" //in include folder
#include "demo_vs2005_c++.h"
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//Open Test Dialog
DialogBox(hInstance,TEXT("IDD_TEST"),NULL,(DLGPROC)TestPageProc);
return 0;
}
//Test Dialog
BOOL APIENTRY TestPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam)
{
SHINITDLGINFO shidi;
TCHAR chToText[256];
TCHAR szWaveFile[256];
static ULONG nStart,nEnd;
switch (message)
{
case WM_INITDIALOG:
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags =SHIDIF_SIPDOWN|SHIDIF_DONEBUTTON|SHIDIF_SIZEDLG;
shidi.hDlg = hdlg;
SHInitDialog(&shidi);
SendDlgItemMessage(hdlg,IDC_EDIT1,WM_SETTEXT,(WPARAM)0,(LPARAM)(LPTSTR)TEXT("欢迎使用语音朗读开发包移动版本!Thanks for using SmartRead Mobile SDK!"));
SendDlgItemMessage(hdlg,IDC_EDIT2,WM_SETTEXT,(WPARAM)0,(LPARAM)(LPTSTR)TEXT("\\demo.wav"));
//COM function
if( FAILED( CoInitializeEx( NULL, COINIT_MULTITHREADED ) ) )
return FALSE;
//Initial cpVoice
hr = CoCreateInstance(CLSID_smVoiceCE, NULL, CLSCTX_ALL, IID_IsmVoice,(LPVOID *)&cpVoice);
if(FAILED(hr))
{
MessageBox(hdlg,TEXT("Error: have not install TTS egnien,please view help"),TEXT("Warning"),MB_OK);
return FALSE;
}
//*********
//Validate Registration Function
//parameter 1 is registration mailbox
//parameter 2 is registration password
//parameter 3 is registration validate code
//parameter 4 is registratio style, not use now
hr = cpVoice->ValidateMobileSDKRegistration(TEXT("support@smartysoft.com"),TEXT("123456789"),TEXT("111-111-111-111"),0);
//Windows Notify Function
//Parameter one is window handle which the edit control highlight the text reading, if set to NULL or 0, highlight function invalid
//Parameter two is window handle which receive the text of reading start and reading over message text
hr = cpVoice->SetNotifyEditWindow((long)GetDlgItem(hdlg,IDC_EDIT1),(long)GetDlgItem(hdlg,IDC_EDIT3));
hr = cpVoice->SetRate(0); //set read rate
hr = cpVoice->SetVolume(100); //set read volume
//Debug function, but it NOT must. The debug information write into demo.txt file.
// you can define the filename as you wish.
//also set the parameter to NULL,delete Log function
hr = cpVoice->SetLogCheck(TEXT("\\demo.txt"));
return (TRUE);
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_EDIT3: //text resource which receive read message, consult SetNotifyEditWindow
switch(HIWORD(wParam))
{
case EN_CHANGE:
TCHAR szMessageText[256];
SendDlgItemMessage(hdlg,IDC_EDIT3,WM_GETTEXT,(WPARAM)256,(LPARAM)(LPTSTR)szMessageText);
//return "TTS_SDK_READ_START" message, show read start, can add custom code
if(lstrcmp(szMessageText,TEXT("TTS_SDK_READ_START"))==0)
MessageBox(hdlg,TEXT("Read start, add your code here"),TEXT("SmartRead Mobile"),MB_OK);
//return "TTS_SDK_READ_END" message, show read over, can add custom code
if(lstrcmp(szMessageText,TEXT("TTS_SDK_READ_END"))==0)
MessageBox(hdlg,TEXT("Read over, add your code here"),TEXT("SmartRead Mobile"),MB_OK);
break;
}
return TRUE;
case IDC_SPEAKTOWAVE:
SendDlgItemMessage(hdlg,IDC_EDIT1,WM_GETTEXT,(WPARAM)256,(LPARAM)(LPTSTR)chToText);
SendDlgItemMessage(hdlg,IDC_EDIT2,WM_GETTEXT,(WPARAM)256,(LPARAM)(LPTSTR)szWaveFile);
//Read to wave file function
//Parameter one show the text of edit control
//Parameter two show the read style,SMSPF_VOICE_CHINESEFEMALE show chinese tts engine. more see the help.
//Parameter three show Wave file name.
//Parameter four,five is reserved parameter,always set 0 or NULL.
if(cpVoice)
hr = cpVoice->SpeakToVoiceFile(chToText+dwReadStart,SMSPF_VOICE_CHINESEFEMALE, szWaveFile,NULL,NULL);
bReading=TRUE;
return TRUE;
case IDC_RATE:
//Voice Rate,lie in -10 - 9
if(cpVoice)
hr = cpVoice->GetRate(&iRate); //Get Voice Rate
iRate=9; //Set Voice Rate.
if(cpVoice)
hr = cpVoice->SetRate(iRate); //Set Voice Rate
return TRUE;
case IDC_VOLUME:
//Voice Volume,lie in 0 - 100
if (cpVoice)
hr = cpVoice->GetVolume(&iVolume); //Get Voice Volume
iVolume=50; //Set Voice Volume
if (cpVoice)
hr = cpVoice->SetVolume(iVolume); //Set Voice Volume
return TRUE;
case IDC_CHINESE_READ: //Mandarin Female reading
dwReadStart=0; //the location begin to read
SendDlgItemMessage(hdlg,IDC_EDIT1,WM_GETTEXT,(WPARAM)256,(LPARAM)(LPTSTR)chToText);
//Mandarin Female Read function
//Parameter one show the text of edit control
//Parameter two show the read style,SMSPF_VOICE_CHINESEFEMALE show chinese tts engine. more see the help.
//Parameter three is text start location, dwReadStart = 0 show read from beginning.
//Parameter four,five is reserved parameter,always set 0 or NULL.
if(cpVoice)
hr = cpVoice->Speak(chToText,SMSPF_VOICE_CHINESEFEMALE,dwReadStart,NULL,NULL);
bReading=TRUE;
return TRUE;
case IDC_ENGLISH_READ: //English Male reading
dwReadStart=0; //the location begin to read
SendDlgItemMessage(hdlg,IDC_EDIT1,WM_GETTEXT,(WPARAM)256,(LPARAM)(LPTSTR)chToText);
//English Male read function
//Parameter one show the text of edit control
//Parameter two show the read style,SMSPF_VOICE_ENGLISHMALE show English tts engine. more see the help.
//Parameter three is text start location, dwReadStart = 0 show read from beginning.
//Parameter four,five is reserved parameter,always set 0 or NULL.
if(cpVoice)
hr = cpVoice->Speak(chToText,SMSPF_VOICE_ENGLISHMALE,dwReadStart,NULL,NULL);
bReading=TRUE;
return TRUE;
case IDC_PAUSERESUME: //Pause/Resume function
if(cpVoice && !bPauseing)
{
hr = cpVoice->Pause(); //Pause function
bPauseing=TRUE;
}
else if(cpVoice && bPauseing)
{
hr = cpVoice->Resume(); //Resume function
bPauseing=FALSE;
}
return TRUE;
case IDC_STOP: //Stop reading
if (cpVoice)
hr = cpVoice->Stop(); //stop function
bReading=FALSE;
return TRUE;
case IDCANCEL:
if (cpVoice && bReading)
hr = cpVoice->Stop();
bReading=FALSE;
if(cpVoice)
{
cpVoice->Release(); //release cpVoice
cpVoice=NULL;
}
//exit COM service
CoUninitialize();
//close the dialog
EndDialog(hdlg,TRUE);
return TRUE;
}
return TRUE;
//Read Notify message, highlight the text which readed
//now WM_USER message has done with in cpVoice inside, consult SetNotifyEditWindow
//here ONLY for compatible with old version
case WM_USER:
SMSPEVENT *eventItem;
eventItem=(SMSPEVENT*)lParam;
switch(LOWORD(wParam))
{
case SMSPEI_START_INPUT_STREAM : //Start message
bReading=TRUE;
bPauseing=FALSE;
SendMessage(GetDlgItem(hdlg,IDC_EDIT1), EM_SETSEL,dwReadStart,dwReadStart);
SendMessage(GetDlgItem(hdlg,IDC_EDIT1), EM_SCROLLCARET,0 ,0);
break;
case SMSPEI_END_INPUT_STREAM: //End message
bReading=FALSE;
bPauseing=FALSE;
SendMessage(GetDlgItem(hdlg,IDC_EDIT1), EM_SETSEL,nEnd,nEnd);
SendMessage(GetDlgItem(hdlg,IDC_EDIT1), EM_SCROLLCARET,0 ,0);
break;
case SMSPEI_SENTENCE_BOUNDARY : //read sentence message,ONLY for sentence message, no word message for new version
nStart = eventItem->wParam+dwReadStart;
nEnd= nStart + eventItem->lParam;
SendMessage(GetDlgItem(hdlg,IDC_EDIT1), EM_SETSEL,nStart ,nEnd);
SendMessage(GetDlgItem(hdlg,IDC_EDIT1), EM_SCROLLCARET,0 ,0);
break;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -