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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 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 {
...
@@ -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.
//remove all special characters.
String
speakText
=
text
.
replaceAll
(
"--*"
,
" "
);
String
speakText
=
text
.
replaceAll
(
"--*"
,
" "
);
// Speak only if the TTS is ready
// Speak only if the TTS is ready
...
@@ -54,7 +54,7 @@ public class Speaker implements TextToSpeech.OnInitListener {
...
@@ -54,7 +54,7 @@ public class Speaker implements TextToSpeech.OnInitListener {
HashMap
<
String
,
String
>
hash
=
new
HashMap
<
String
,
String
>();
HashMap
<
String
,
String
>
hash
=
new
HashMap
<
String
,
String
>();
hash
.
put
(
TextToSpeech
.
Engine
.
KEY_PARAM_STREAM
,
hash
.
put
(
TextToSpeech
.
Engine
.
KEY_PARAM_STREAM
,
String
.
valueOf
(
AudioManager
.
STREAM_MUSIC
));
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
);
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
...
@@ -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*/
/*According to this flag we'll close the conversation from mobile side. We'll get this flag in chat response*/
private
boolean
mIsConversationEnd
;
private
boolean
mIsConversationEnd
;
private
String
mNewMessageUtteranceId
;
@Override
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
menuItem
)
{
public
boolean
onOptionsItemSelected
(
MenuItem
menuItem
)
{
if
(
menuItem
.
getItemId
()
==
android
.
R
.
id
.
home
)
{
if
(
menuItem
.
getItemId
()
==
android
.
R
.
id
.
home
)
{
...
@@ -228,7 +230,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
...
@@ -228,7 +230,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
droidSpeech
.
closeDroidSpeechOperations
();
droidSpeech
.
closeDroidSpeechOperations
();
}
}
speaker
.
allow
(
true
);
speaker
.
allow
(
true
);
speaker
.
speak
(
message
);
speaker
.
speak
(
message
,
mNewMessageUtteranceId
);
}
}
mMessages
.
add
(
chatBotHistory
);
mMessages
.
add
(
chatBotHistory
);
...
@@ -338,21 +340,23 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
...
@@ -338,21 +340,23 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
username
=
data
.
getString
(
NEW_MESSAGE_USER_NAME
);
username
=
data
.
getString
(
NEW_MESSAGE_USER_NAME
);
message
=
data
.
getString
(
NEW_MESSAGE_MESSAGE
);
message
=
data
.
getString
(
NEW_MESSAGE_MESSAGE
);
mIsConversationEnd
=
data
.
getBoolean
(
IS_END_OF_INTENT
);
mIsConversationEnd
=
data
.
getBoolean
(
IS_END_OF_INTENT
);
mNewMessageUtteranceId
=
String
.
valueOf
(
System
.
currentTimeMillis
());
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
CatalogueLog
.
e
(
e
.
getMessage
());
CatalogueLog
.
e
(
e
.
getMessage
());
return
;
return
;
}
}
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByName
(
username
);
if
(!
message
.
isEmpty
())
{
if
(
localChatBotUser
==
null
)
{
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByName
(
username
);
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
if
(
localChatBotUser
==
null
)
{
.
setName
(
username
)
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setUserSysId
(
ChatBotUser
.
CHAT_BOT_SYS_ID
)
.
setName
(
username
)
.
build
();
.
setUserSysId
(
ChatBotUser
.
CHAT_BOT_SYS_ID
)
ChatBotUserManager
.
save
(
chatBotUser
);
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
addMessage
(
username
,
message
);
}
}
addMessage
(
username
,
message
);
}
}
});
});
}
}
...
@@ -458,6 +462,18 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
...
@@ -458,6 +462,18 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
speaker
.
getTTS
().
setOnUtteranceProgressListener
(
new
UtteranceProgressListener
()
{
speaker
.
getTTS
().
setOnUtteranceProgressListener
(
new
UtteranceProgressListener
()
{
@Override
@Override
public
void
onDone
(
String
utteranceId
)
{
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
))
{
if
(!
mIsConversationEnd
&&
(!
speaker
.
isSpeaking
()
&&
droidSpeech
!=
null
))
{
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
@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