mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-06 19:16:43 +02:00
Tidy object management
This commit is contained in:
parent
a45d4b2d7d
commit
69b1c4273f
2 changed files with 16 additions and 12 deletions
|
@ -21,7 +21,6 @@ SpeechRecognizer::SpeechRecognizer() :
|
|||
_enabled(false),
|
||||
_commands(),
|
||||
_comInitialized(false),
|
||||
_speechRecognizer(NULL),
|
||||
_speechRecognizerContext(NULL),
|
||||
_speechRecognizerGrammar(NULL),
|
||||
_commandRecognizedEvent(NULL),
|
||||
|
@ -32,17 +31,23 @@ SpeechRecognizer::SpeechRecognizer() :
|
|||
if (SUCCEEDED(hr)) {
|
||||
_comInitialized = true;
|
||||
}
|
||||
|
||||
_commandRecognizedNotifier = new QWinEventNotifier();
|
||||
connect(_commandRecognizedNotifier, SIGNAL(activated(HANDLE)), SLOT(notifyCommandRecognized(HANDLE)));
|
||||
}
|
||||
|
||||
SpeechRecognizer::~SpeechRecognizer() {
|
||||
if (_speechRecognizerGrammar) {
|
||||
_speechRecognizerGrammar.Release();
|
||||
}
|
||||
|
||||
if (_enabled) {
|
||||
_speechRecognizerContext.Release();
|
||||
}
|
||||
|
||||
if (_comInitialized) {
|
||||
::CoUninitialize();
|
||||
}
|
||||
|
||||
if (_speechRecognizerGrammar) {
|
||||
_speechRecognizerGrammar.Release();
|
||||
}
|
||||
}
|
||||
|
||||
void SpeechRecognizer::handleCommandRecognized(const char* command) {
|
||||
|
@ -71,14 +76,13 @@ void SpeechRecognizer::setEnabled(bool enabled) {
|
|||
}
|
||||
if (SUCCEEDED(hr)) {
|
||||
_commandRecognizedEvent = _speechRecognizerContext->GetNotifyEventHandle();
|
||||
if (_commandRecognizedEvent == NULL) {
|
||||
if (_commandRecognizedEvent) {
|
||||
_commandRecognizedNotifier->setHandle(_commandRecognizedEvent);
|
||||
_commandRecognizedNotifier->setEnabled(true);
|
||||
} else {
|
||||
hr = S_FALSE;
|
||||
}
|
||||
}
|
||||
if (SUCCEEDED(hr)) {
|
||||
_commandRecognizedNotifier = new QWinEventNotifier(_commandRecognizedEvent);
|
||||
connect(_commandRecognizedNotifier, SIGNAL(activated(HANDLE)), SLOT(notifyCommandRecognized(HANDLE)));
|
||||
}
|
||||
|
||||
// Set which events to be notified of.
|
||||
if (SUCCEEDED(hr)) {
|
||||
|
@ -96,6 +100,7 @@ void SpeechRecognizer::setEnabled(bool enabled) {
|
|||
_enabled = SUCCEEDED(hr);
|
||||
|
||||
} else {
|
||||
_commandRecognizedNotifier->setEnabled(false);
|
||||
_speechRecognizerContext.Release();
|
||||
}
|
||||
|
||||
|
@ -144,7 +149,7 @@ void SpeechRecognizer::reloadCommands() {
|
|||
}
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
hr = _speechRecognizerGrammar->Commit(0);
|
||||
hr = _speechRecognizerGrammar->Commit(NULL);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
|
|
|
@ -52,7 +52,6 @@ private:
|
|||
void* _speechRecognizer;
|
||||
#elif defined(Q_OS_WIN)
|
||||
bool _comInitialized;
|
||||
CComPtr<ISpRecognizer> _speechRecognizer;
|
||||
CComPtr<ISpRecoContext> _speechRecognizerContext;
|
||||
CComPtr<ISpRecoGrammar> _speechRecognizerGrammar;
|
||||
HANDLE _commandRecognizedEvent;
|
||||
|
|
Loading…
Reference in a new issue