summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTuomas Tuononen <tuomas.tuononen@code-q.fi>2015-10-01 16:43:48 +0300
committerTuomas Tuononen <tuomas.tuononen@code-q.fi>2015-10-16 12:56:29 +0000
commitcee89070011a5b0d5f907a6acaf965f7cc1eecd1 (patch)
tree77eaaac5427d59df53b2a32d6c94726b5cc809e7
parent0d6afbd08f155569eb4e0e395940e6a90e4e0062 (diff)
SpeechRecognition: Fix wrong state transitions
Do not allow transition from ListeningStoppingState to either ListeningState or MutedState. Also move straight to IdleState on abortListening() or reset() when possible. Details: If listening is stopped immediately after starting it, the expected state sequence is: IdleState -> ListeningStartingState -> ListeningStoppingState -> IdleState In this case signal listeningStarted() is now emitted on ListeningStoppingState (was: ListeningState). If listening was started, stopped and aborted in a fast sequence, signal listeningStopped() was emitted even when listeningStarted() was not. The expected behavior for abortListening() or reset() is to move straight to IdleState in this case. Change-Id: I3d3b9d096ad38c1bdf2f5ef7958776f2dd4a1496 Reviewed-by: Andrew Knight <andrew.knight@intopalo.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
-rwxr-xr-xsrc/asr/qspeechrecognition.cpp30
-rwxr-xr-xsrc/asr/qspeechrecognition_p.h1
2 files changed, 19 insertions, 12 deletions
diff --git a/src/asr/qspeechrecognition.cpp b/src/asr/qspeechrecognition.cpp
index e0ffe75..ad7c39f 100755
--- a/src/asr/qspeechrecognition.cpp
+++ b/src/asr/qspeechrecognition.cpp
@@ -519,10 +519,9 @@ void QSpeechRecognition::abortListening()
d->m_session++;
emit d->m_managerInterface->setSession(d->m_session);
emit d->m_managerInterface->abortListening();
- if (d->m_state == QSpeechRecognition::ListeningState
- || d->m_state == QSpeechRecognition::MutedState)
+ if (d->m_listening)
d->setState(QSpeechRecognition::ListeningStoppingState);
- else if (d->m_state != QSpeechRecognition::ListeningStoppingState)
+ else
d->setState(QSpeechRecognition::IdleState);
}
@@ -579,10 +578,9 @@ void QSpeechRecognition::reset()
emit d->m_managerInterface->setSession(d->m_session);
emit d->m_managerInterface->reset();
d->m_grammar = 0;
- if (d->m_state == QSpeechRecognition::ListeningState
- || d->m_state == QSpeechRecognition::MutedState)
+ if (d->m_listening)
d->setState(QSpeechRecognition::ListeningStoppingState);
- else if (d->m_state != QSpeechRecognition::ListeningStoppingState)
+ else
d->setState(QSpeechRecognition::IdleState);
}
@@ -614,6 +612,7 @@ void QSpeechRecognition::dispatchMessage(const QString &message, const QVariantM
QSpeechRecognitionPrivate::QSpeechRecognitionPrivate():
m_managerInterface(new QSpeechRecognitionManagerInterface(this)),
m_session(0),
+ m_listening(false),
m_muted(false),
m_state(QSpeechRecognition::IdleState),
m_managerThread(new QThread()),
@@ -692,7 +691,9 @@ void QSpeechRecognitionPrivate::onListeningStarted(int session)
Q_Q(QSpeechRecognition);
qCDebug(lcSpeechAsr) << "QSpeechRecognitionPrivate::onListeningStarted()";
if (session == m_session) {
- setState(QSpeechRecognition::ListeningState);
+ if (m_state != QSpeechRecognition::ListeningStoppingState)
+ setState(QSpeechRecognition::ListeningState);
+ m_listening = true;
emit q->listeningStarted(m_grammar->name());
}
}
@@ -703,7 +704,8 @@ void QSpeechRecognitionPrivate::onListeningMuted(int session)
qCDebug(lcSpeechAsr) << "QSpeechRecognitionPrivate::onListeningMuted()";
if (session == m_session) {
QSpeechRecognition::State state = m_state;
- setState(QSpeechRecognition::MutedState);
+ if (state != QSpeechRecognition::ListeningStoppingState)
+ setState(QSpeechRecognition::MutedState);
if (state == QSpeechRecognition::ListeningState)
emit q->listeningStopped(false);
}
@@ -714,6 +716,7 @@ void QSpeechRecognitionPrivate::onProcessingStarted(int session)
Q_Q(QSpeechRecognition);
qCDebug(lcSpeechAsr) << "QSpeechRecognitionPrivate::onProcessingStarted()";
if (session == m_session) {
+ Q_ASSERT(m_listening);
setState(QSpeechRecognition::ProcessingState);
emit q->listeningStopped(true);
}
@@ -724,12 +727,12 @@ void QSpeechRecognitionPrivate::onNotListening(int session)
Q_Q(QSpeechRecognition);
qCDebug(lcSpeechAsr) << "QSpeechRecognitionPrivate::onNotListening()";
if (session == m_session) {
- QSpeechRecognition::State state = m_state;
+ bool wasListening = m_listening;
setState(QSpeechRecognition::IdleState);
- if (state == QSpeechRecognition::ListeningState
- || state == QSpeechRecognition::ListeningStoppingState) {
+ // Signal listeningStarted() was never emitted if listening was started and stopped
+ // while muted. In this case listeningStopped() should not be emitted either.
+ if (wasListening)
emit q->listeningStopped(false);
- }
}
}
@@ -810,6 +813,9 @@ void QSpeechRecognitionPrivate::onUnmuteTimeout()
void QSpeechRecognitionPrivate::setState(QSpeechRecognition::State state)
{
Q_Q(QSpeechRecognition);
+ if (state != QSpeechRecognition::ListeningState
+ && state != QSpeechRecognition::ListeningStoppingState)
+ m_listening = false;
if (state != m_state) {
m_state = state;
qCDebug(lcSpeechAsr) << m_state;
diff --git a/src/asr/qspeechrecognition_p.h b/src/asr/qspeechrecognition_p.h
index e02dc38..60f01ab 100755
--- a/src/asr/qspeechrecognition_p.h
+++ b/src/asr/qspeechrecognition_p.h
@@ -92,6 +92,7 @@ private:
void setState(QSpeechRecognition::State state);
QSpeechRecognitionManagerInterface *m_managerInterface;
int m_session;
+ bool m_listening;
bool m_muted;
QSpeechRecognition::State m_state;
QThread *m_managerThread;