Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Krishna Vemulavada
/
vera_2.1_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
27511e1a
authored
Apr 19, 2018
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Fixed - Make mobile app stop listening to user based on server flag.
parent
0374c45b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
app/src/main/java/com/vsoft/servicenow/chat/Speaker.java
app/src/main/java/com/vsoft/servicenow/ui/ChatActivity.java
app/src/main/java/com/vsoft/servicenow/chat/Speaker.java
View file @
27511e1a
...
...
@@ -45,7 +45,7 @@ public class Speaker implements TextToSpeech.OnInitListener {
}
}
public
void
speak
(
String
text
)
{
public
void
speak
(
String
text
,
String
utteranceId
)
{
//remove all special characters.
String
speakText
=
text
.
replaceAll
(
"--*"
,
" "
);
// Speak only if the TTS is ready
...
...
@@ -54,7 +54,7 @@ public class Speaker implements TextToSpeech.OnInitListener {
HashMap
<
String
,
String
>
hash
=
new
HashMap
<
String
,
String
>();
hash
.
put
(
TextToSpeech
.
Engine
.
KEY_PARAM_STREAM
,
String
.
valueOf
(
AudioManager
.
STREAM_MUSIC
));
hash
.
put
(
TextToSpeech
.
Engine
.
KEY_PARAM_UTTERANCE_ID
,
""
+
System
.
currentTimeMillis
()
);
hash
.
put
(
TextToSpeech
.
Engine
.
KEY_PARAM_UTTERANCE_ID
,
utteranceId
);
tts
.
speak
(
Util
.
fromHtml
(
speakText
).
toString
(),
TextToSpeech
.
QUEUE_ADD
,
hash
);
}
}
...
...
app/src/main/java/com/vsoft/servicenow/ui/ChatActivity.java
View file @
27511e1a
...
...
@@ -91,6 +91,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
/*According to this flag we'll close the conversation from mobile side. We'll get this flag in chat response*/
private
boolean
mIsConversationEnd
;
private
String
mNewMessageUtteranceId
;
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
menuItem
)
{
if
(
menuItem
.
getItemId
()
==
android
.
R
.
id
.
home
)
{
...
...
@@ -228,7 +230,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
droidSpeech
.
closeDroidSpeechOperations
();
}
speaker
.
allow
(
true
);
speaker
.
speak
(
message
);
speaker
.
speak
(
message
,
mNewMessageUtteranceId
);
}
mMessages
.
add
(
chatBotHistory
);
...
...
@@ -338,22 +340,24 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
username
=
data
.
getString
(
NEW_MESSAGE_USER_NAME
);
message
=
data
.
getString
(
NEW_MESSAGE_MESSAGE
);
mIsConversationEnd
=
data
.
getBoolean
(
IS_END_OF_INTENT
);
mNewMessageUtteranceId
=
String
.
valueOf
(
System
.
currentTimeMillis
());
}
catch
(
JSONException
e
)
{
CatalogueLog
.
e
(
e
.
getMessage
());
return
;
}
if
(!
message
.
isEmpty
())
{
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByName
(
username
);
if
(
localChatBotUser
==
null
)
{
if
(
localChatBotUser
==
null
)
{
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setName
(
username
)
.
setUserSysId
(
ChatBotUser
.
CHAT_BOT_SYS_ID
)
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
addMessage
(
username
,
message
);
}
}
});
}
};
...
...
@@ -458,6 +462,18 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
speaker
.
getTTS
().
setOnUtteranceProgressListener
(
new
UtteranceProgressListener
()
{
@Override
public
void
onDone
(
String
utteranceId
)
{
/*Start Code
Sometime speaker is not getting stop that's why it is breaking.
* We need to forcefully stop it.*/
long
utteranceIdLong
=
Long
.
parseLong
(
utteranceId
);
long
messageUtteranceId
=
Long
.
parseLong
(
mNewMessageUtteranceId
);
if
(
utteranceIdLong
==
messageUtteranceId
&&
speaker
!=
null
&&
speaker
.
isSpeaking
())
{
speaker
.
stop
();
}
/*End Code*/
if
(!
mIsConversationEnd
&&
(!
speaker
.
isSpeaking
()
&&
droidSpeech
!=
null
))
{
runOnUiThread
(
new
Runnable
()
{
@Override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment