1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <QObject> #include <QLibrary> #include <functional>
typedef enum { SPEECH_ERROR_OCCURRED = 1, SPEECH_RECOGNITION_STARTED = 2, SPEECH_RECOGNIZING = 3, SPEECH_RECOGNIZED = 4, SPEECH_RECOGNITION_COMPLETED = 5, SPEECH_SYNTHESIS_STARTED = 6, SPEECH_SYNTHESIZING = 7, SPEECH_SYNTHESIS_COMPLETED = 8, } SpeechResultReason;
typedef struct _SpeechRecognitionSession SpeechRecognitionSession; typedef struct _SpeechRecognitionResult SpeechRecognitionResult; typedef struct _SpeechSynthesisResult SpeechSynthesisResult; typedef struct _AudioConfig AudioConfig;
typedef void (*SpeechRecognitionResultCallback)(SpeechRecognitionResult *result, void *user_data); typedef void (*SpeechSynthesisResultCallback)(SpeechSynthesisResult *result, void *user_data); typedef void* (*CreateSessionFunc)(); typedef int (*InitSessionFunc)(void*); typedef const char *(*GetTextFunc)(SpeechRecognitionResult *result); typedef SpeechResultReason(*GetReasonFunc)(SpeechRecognitionResult *result); typedef void (*SetCallbackFunc)(void*, void(*callback)(SpeechRecognitionResult*, void*), void*); typedef void (*StartRecognitionFunc)(void*); typedef void (*StopRecognitionFunc)(void*); typedef void (*SetAudioConfigFunc)(void*, void*); typedef AudioConfig* (*CreateAudioConfigFunc)();
class QMutex; class PUBLICDATA_EXPORT Speech : public QObject { Q_OBJECT public: static Speech* getInstance(); void beginListening(); void endListening(); bool isSpeechSetup(); bool isSpeechListening();
protected: explicit Speech(QObject *parent = nullptr);
signals: void sigSpeechCallBack(const char*); void warning(QString);
private: void loadSpeechLibrary(); static void callback(SpeechRecognitionResult *result, void *user_data);
private: static Speech* m_pSpeech; static QMutex mutex_m;
private: QLibrary m_speechLibrary; CreateSessionFunc speech_recognizer_create_session = nullptr; InitSessionFunc speech_recognizer_init_session = nullptr; SetCallbackFunc speech_recognizer_result_set_callback = nullptr; StartRecognitionFunc speech_recognizer_start_continuous_recognition_async = nullptr; StopRecognitionFunc speech_recognizer_stop_continuous_recognition_async = nullptr; GetTextFunc speech_recognition_result_get_text = nullptr; GetReasonFunc speech_recognition_result_get_reason = nullptr; CreateAudioConfigFunc audio_config_create_continuous_audio_input_from_default_microphone = nullptr; SetAudioConfigFunc speech_recognizer_set_audio_config = nullptr;
void *m_session = nullptr;
bool m_bSpeechSetup; bool m_isListening; };
|