Skip to content

Commit 46fc979

Browse files
author
spoeck
committed
fix #45
1 parent ae5c574 commit 46fc979

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

example/package-lock.json

+6-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
"devDependencies": {
1616
"metro-react-native-babel-preset": "0.48.1"
1717
}
18-
}
18+
}

index.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,33 @@ dialogflow2.setConfiguration = async function (clientEmail, privateKey, language
5353
dialogflow2.sessionId = dialogflow2.sessionId ? dialogflow2.sessionId : dialogflow2.guid();
5454

5555
// set listeners
56-
Voice.onSpeechStart = (c) => dialogflow2.onListeningStarted(c);
57-
Voice.onSpeechEnd = (c) => dialogflow2.onListeningFinished(c);
58-
Voice.onSpeechVolumeChanged = (c) => dialogflow2.onAudioLevel(c);
56+
Voice.onSpeechStart = (c) => {
57+
dialogflow2.speechResult = null;
58+
if (dialogflow2.onListeningStarted) {
59+
dialogflow2.onListeningStarted(c);
60+
}
61+
}
62+
63+
Voice.onSpeechEnd = (c) => {
64+
65+
if (dialogflow2.speechResult) {
66+
dialogflow2.requestQuery(dialogflow2.speechResult[0], dialogflow2.onResult, dialogflow2.onError);
67+
}
68+
69+
if (dialogflow2.onListeningFinished) {
70+
dialogflow2.onListeningFinished(c);
71+
}
72+
}
73+
74+
Voice.onSpeechVolumeChanged = (c) => {
75+
if (dialogflow2.onAudioLevel) {
76+
dialogflow2.onAudioLevel(c);
77+
}
78+
}
5979

6080
Voice.onSpeechResults = (result) => {
6181
if (result.value) {
62-
dialogflow2.requestQuery(result.value[0], dialogflow2.onResult, dialogflow2.onError);
82+
dialogflow2.speechResult = result.value;
6383
}
6484
}
6585
}

0 commit comments

Comments
 (0)