SpeechSampleDlg.cpp
上传用户:zhaopin
上传日期:2007-01-07
资源大小:79k
文件大小:4k
源码类别:

语音合成与识别

开发平台:

Visual C++

  1. // SpeechSampleDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SpeechSample.h"
  5. #include "SpeechSampleDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSpeechSampleDlg dialog
  13. CSpeechSampleDlg::CSpeechSampleDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CSpeechSampleDlg::IDD, pParent), m_speech(this)
  15. {
  16. //{{AFX_DATA_INIT(CSpeechSampleDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  20. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  21. }
  22. void CSpeechSampleDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CSpeechSampleDlg)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(CSpeechSampleDlg, CDialog)
  30. //{{AFX_MSG_MAP(CSpeechSampleDlg)
  31. ON_WM_PAINT()
  32. ON_WM_QUERYDRAGICON()
  33. ON_BN_CLICKED(IDSPEAK, OnSpeak)
  34. ON_BN_CLICKED(IDVOICE, OnVoice)
  35. ON_WM_CLOSE()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CSpeechSampleDlg message handlers
  40. BOOL CSpeechSampleDlg::OnInitDialog()
  41. {
  42. CDialog::OnInitDialog();
  43. if (!m_speech.Init())
  44. return FALSE;
  45. // Set the icon for this dialog.  The framework does this automatically
  46. //  when the application's main window is not a dialog
  47. SetIcon(m_hIcon, TRUE); // Set big icon
  48. SetIcon(m_hIcon, FALSE); // Set small icon
  49. // TODO: Add extra initialization here
  50. return TRUE;  // return TRUE  unless you set the focus to a control
  51. }
  52. // If you add a minimize button to your dialog, you will need the code below
  53. //  to draw the icon.  For MFC applications using the document/view model,
  54. //  this is automatically done for you by the framework.
  55. void CSpeechSampleDlg::OnPaint() 
  56. {
  57. if (IsIconic())
  58. {
  59. CPaintDC dc(this); // device context for painting
  60. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  61. // Center icon in client rectangle
  62. int cxIcon = GetSystemMetrics(SM_CXICON);
  63. int cyIcon = GetSystemMetrics(SM_CYICON);
  64. CRect rect;
  65. GetClientRect(&rect);
  66. int x = (rect.Width() - cxIcon + 1) / 2;
  67. int y = (rect.Height() - cyIcon + 1) / 2;
  68. // Draw the icon
  69. dc.DrawIcon(x, y, m_hIcon);
  70. }
  71. else
  72. {
  73. CDialog::OnPaint();
  74. }
  75. }
  76. // The system calls this to obtain the cursor to display while the user drags
  77. //  the minimized window.
  78. HCURSOR CSpeechSampleDlg::OnQueryDragIcon()
  79. {
  80. return (HCURSOR) m_hIcon;
  81. }
  82. void CSpeechSampleDlg::OnSpeak() 
  83. {
  84. CString text;
  85. CEdit* editCtrl = (CEdit*) GetDlgItem(IDC_SPEAKEDIT);
  86. editCtrl->GetWindowText(text);
  87. m_speech.Say(text);
  88. }
  89. void CSpeechSampleDlg::OnVoice() 
  90. {
  91. }
  92. void CSpeechSampleDlg::OnClose() 
  93. {
  94. CDialog::OnClose();
  95. m_speech.Terminate();
  96. }
  97. void CSpeechSampleDlg::OnOK() 
  98. {
  99. m_speech.Terminate();
  100. CDialog::OnOK();
  101. }
  102. // CSampleSpeech
  103. BOOL CSampleSpeech::OnAudioStart (timestamp_t qTimeStamp)
  104. {
  105. CButton* speakButton = (CButton*) m_dialog->GetDlgItem(IDSPEAK);
  106. CButton* voiceButton = (CButton*) m_dialog->GetDlgItem(IDVOICE);
  107. CButton* exitButton = (CButton*) m_dialog->GetDlgItem(IDOK);
  108. speakButton->EnableWindow(FALSE);
  109. voiceButton->EnableWindow(FALSE);
  110. exitButton->EnableWindow(FALSE);
  111. return TRUE;
  112. }
  113. BOOL CSampleSpeech::OnAudioStop (timestamp_t qTimeStamp)
  114. {
  115. CButton* speakButton = (CButton*) m_dialog->GetDlgItem(IDSPEAK);
  116. CButton* voiceButton = (CButton*) m_dialog->GetDlgItem(IDVOICE);
  117. CButton* exitButton = (CButton*) m_dialog->GetDlgItem(IDOK);
  118. speakButton->EnableWindow(TRUE);
  119. voiceButton->EnableWindow(TRUE);
  120. exitButton->EnableWindow(TRUE);
  121. return TRUE;
  122. }