RealtimeSpeechRecognitionDlg.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // RealtimeSpeechRecognitionDlg.h : header file
  2. //
  3. #pragma once
  4. #include <string>
  5. #include <vector>
  6. #include "portaudio.h"
  7. #include "sherpa-ncnn/c-api/c-api.h"
  8. class Microphone {
  9. public:
  10. Microphone();
  11. ~Microphone();
  12. };
  13. class RecognizerThread;
  14. // CRealtimeSpeechRecognitionDlg dialog
  15. class CRealtimeSpeechRecognitionDlg : public CDialogEx {
  16. // Construction
  17. public:
  18. CRealtimeSpeechRecognitionDlg(
  19. CWnd *pParent = nullptr); // standard constructor
  20. ~CRealtimeSpeechRecognitionDlg();
  21. // Dialog Data
  22. #ifdef AFX_DESIGN_TIME
  23. enum { IDD = IDD_REALTIMESPEECHRECOGNITION_DIALOG };
  24. #endif
  25. protected:
  26. virtual void DoDataExchange(CDataExchange *pDX); // DDX/DDV support
  27. // Implementation
  28. protected:
  29. HICON m_hIcon;
  30. // Generated message map functions
  31. virtual BOOL OnInitDialog();
  32. afx_msg void OnPaint();
  33. afx_msg HCURSOR OnQueryDragIcon();
  34. DECLARE_MESSAGE_MAP()
  35. public:
  36. afx_msg void OnBnClickedOk();
  37. int RunThread();
  38. private:
  39. Microphone mic_;
  40. SherpaNcnnRecognizer *recognizer_ = nullptr;
  41. PaStream *pa_stream_ = nullptr;
  42. RecognizerThread *thread_ = nullptr;
  43. public:
  44. bool started_ = false;
  45. SherpaNcnnStream *stream_ = nullptr;
  46. public:
  47. CButton my_btn_;
  48. CEdit my_text_;
  49. private:
  50. void AppendTextToEditCtrl(const std::string &s);
  51. void AppendLineToMultilineEditCtrl(const std::string &s);
  52. void InitMicrophone();
  53. bool Exists(const std::string &filename);
  54. void InitRecognizer();
  55. };
  56. class RecognizerThread : public CWinThread {
  57. public:
  58. RecognizerThread(CRealtimeSpeechRecognitionDlg *dlg) : dlg_(dlg) {}
  59. virtual BOOL InitInstance() { return TRUE; }
  60. virtual int Run() { return dlg_->RunThread(); }
  61. private:
  62. CRealtimeSpeechRecognitionDlg *dlg_;
  63. };