Skip to content

Commit 636243a

Browse files
authored
Merge pull request #128 from watson-developer-cloud/develop
Unity Watson SDK 0.8.0
2 parents 03488e0 + 1633d97 commit 636243a

File tree

12 files changed

+428
-532
lines changed

12 files changed

+428
-532
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
Change Log
22
==========
3+
## Version 0.8.0
4+
_2016-08-12_
5+
6+
* Fixed: Removed tag stripping from `ToSpeech()` method of the `TextToSpeech` service.
7+
* New: The `Conversation` service now accepts full conversation payload in overloaded `Message()` method.
8+
* Fixed: Removed `SetLastWriteTime()` for Android platform in the data cache because of a known android issue.
9+
```https://code.google.com/p/android/issues/detail?id=15480```
10+
11+
312
## Version 0.7.0
413
_2016-07-29_
514

Config.json.enc

0 Bytes
Binary file not shown.

Examples/ServiceExamples/Scripts/ExampleConversation.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,31 @@ public class ExampleConversation : MonoBehaviour
2929

3030
void Start () {
3131
LogSystem.InstallDefaultReactors();
32-
m_WorkspaceID = Config.Instance.GetVariableValue("ConversationV1_WorkspaceID");
32+
m_WorkspaceID = Config.Instance.GetVariableValue("ConversationV1_ID");
3333
Debug.Log("User: " + m_Input);
3434

35-
m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage);
35+
// Message with input only
36+
//m_Conversation.Message(OnMessage, m_WorkspaceID, m_Input);
37+
38+
// Message by creating message request
39+
//MessageRequest messageRequest = new MessageRequest();
40+
//messageRequest.inputText = m_Input;
41+
//m_Conversation.Message(OnMessage, m_WorkspaceID, messageRequest);
42+
43+
// Message by passing input, alternate intents and conversationID
44+
m_Conversation.Message(OnMessage, m_WorkspaceID, m_Input, false, null);
3645
}
3746

38-
void OnMessage (MessageResponse resp)
47+
void OnMessage (MessageResponse resp, string customData)
3948
{
4049
if(resp != null)
4150
{
42-
foreach(MessageIntent mi in resp.intents)
51+
foreach(Intent mi in resp.intents)
4352
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
4453

45-
if(resp.output != null && !string.IsNullOrEmpty(resp.output.text))
46-
Debug.Log("response: " + resp.output.text);
54+
if(resp.output != null && resp.output.text.Length > 0)
55+
foreach(string txt in resp.output.text)
56+
Debug.Log("output: " + txt);
4757
}
4858
else
4959
{

Examples/ServiceExamples/Scripts/ExampleTextToSpeech.cs

100644100755
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
public class ExampleTextToSpeech : MonoBehaviour
2222
{
2323
TextToSpeech m_TextToSpeech = new TextToSpeech();
24-
string m_TestString = "Hello! This is Text to Speech!";
24+
string m_TestString = "<speak version=\"1.0\"><say-as interpret-as=\"letters\">I'm sorry</say-as>. <prosody pitch=\"150Hz\">This is Text to Speech!</prosody></express-as><express-as type=\"GoodNews\">I'm sorry. This is Text to Speech!</express-as></speak>";
2525

26-
void Start ()
26+
27+
void Start ()
2728
{
28-
m_TextToSpeech.Voice = VoiceType.en_GB_Kate;
29-
m_TextToSpeech.ToSpeech(m_TestString, HandleToSpeechCallback);
29+
m_TextToSpeech.Voice = VoiceType.en_US_Allison;
30+
m_TextToSpeech.ToSpeech(m_TestString, HandleToSpeechCallback, true);
3031
}
3132

3233
void HandleToSpeechCallback (AudioClip clip)

Examples/ServiceExamples/ServiceExamples.unity

Lines changed: 29 additions & 51 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,20 @@ void HandleOnRecognize (SpeechResultList result)
9696
```
9797

9898
### Text to Speech
99-
Use the [Text to Speech][text_to_speech] service to get the available voices to synthesize.
99+
Use the [Text to Speech][text_to_speech] service to get the available voices to synthesize. The Text to Speech service also supports Speech Synthesis Markup Language ([SSML][ssml]). In addition, the service supports a service-specific [expressive SSML][expressive_ssml] element.
100100

101101
```cs
102102
TextToSpeech m_TextToSpeech = new TextToSpeech();
103103
string m_TestString = "Hello! This is Text to Speech!";
104+
string m_ExpressiveText = "<speak version=\"1.0\"><prosody pitch=\"150Hz\">Hello! This is the </prosody><say-as interpret-as=\"letters\">IBM</say-as> Watson <express-as type=\"GoodNews\">Unity</express-as></prosody><say-as interpret-as=\"letters\">SDK</say-as>!</speak>";
104105

105106
void Start ()
106107
{
107108
m_TextToSpeech.Voice = VoiceType.en_GB_Kate;
108109
m_TextToSpeech.ToSpeech(m_TestString, HandleToSpeechCallback);
110+
111+
m_TextToSpeech.Voice = VoiceType.en_US_Allison;
112+
m_TextToSpeech.ToSpeech(m_ExpressiveText, HandleToSpeechCallback);
109113
}
110114

111115
void HandleToSpeechCallback (AudioClip clip)
@@ -335,7 +339,7 @@ void Start () {
335339
```
336340

337341
### Conversation
338-
With the IBM Watson™ [Conversation][conversation] service you can create cognitive agents - virtual agents that combine machine learning, natural language understanding, and integrated dialog scripting tools to provide outstanding customer engagements. A workspace should be created using [Conversation tooling][conversation_tooling] and a variable `ConversationV1_ID` should be set in the Config Editor with the Workspace ID.
342+
With the IBM Watson™ [Conversation][conversation] service you can create cognitive agents - virtual agents that combine machine learning, natural language understanding, and integrated dialog scripting tools to provide outstanding customer engagements. A workspace should be created using [Conversation tooling][conversation_tooling] and a variable `ConversationV1_ID` should be set in the Config Editor with the Workspace ID. This is required for the service status check in the `Config Editor`.
339343

340344
```cs
341345
private Conversation m_Conversation = new Conversation();
@@ -344,7 +348,7 @@ private string m_Input = "Can you unlock the door?";
344348

345349
void Start () {
346350
Debug.Log("User: " + m_Input);
347-
m_Conversation.Message(m_WorkspaceID, m_Input, OnMessage);
351+
m_Conversation.Message(OnMessage, m_WorkspaceID, m_Input);
348352
}
349353

350354
void OnMessage (DataModels.MessageResponse resp)
@@ -2134,3 +2138,5 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md).
21342138
[conversation_tooling]: https://www.ibmwatsonconversation.com
21352139
[retrieve_and_rank]: http://www.ibm.com/watson/developercloud/retrieve-and-rank/api/v1/
21362140
[document_conversion]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/document-conversion/api/v1/
2141+
[expressive_ssml]: http://www.ibm.com/watson/developercloud/doc/text-to-speech/http.shtml#expressive
2142+
[ssml]: http://www.ibm.com/watson/developercloud/doc/text-to-speech/SSML.shtml

Scripts/Services/Conversation/Conversation.cs

Lines changed: 100 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -33,98 +33,34 @@ namespace IBM.Watson.DeveloperCloud.Services.Conversation.v1
3333
public class Conversation : IWatsonService
3434
{
3535
#region Public Types
36-
/// <summary>
37-
/// The callback for GetWorkspaces().
38-
/// </summary>
39-
public delegate void OnGetWorkspaces(Workspaces workspaces);
40-
/// <summary>
41-
/// The callback for Message().
42-
/// </summary>
43-
/// <param name="success"></param>
44-
public delegate void OnMessageCallback(bool success);
45-
/// <summary>
46-
/// The callback delegate for the Converse() function.
47-
/// </summary>
48-
/// <param name="resp">The response object to a call to Converse().</param>
49-
public delegate void OnMessage(MessageResponse resp);
50-
5136
#endregion
5237

5338
#region Public Properties
5439
#endregion
5540

5641
#region Private Data
5742
private const string SERVICE_ID = "ConversationV1";
43+
private const string SERVICE_MESSAGE = "/v1/workspaces";
5844
private static fsSerializer sm_Serializer = new fsSerializer();
59-
#endregion
60-
/*
61-
#region Workspaces
62-
/// <summary>
63-
/// Gets the available workspaces for the Conversation service
64-
/// </summary>
65-
/// <returns>Returns true if request has been sent.</returns>
66-
/// <param name="callback">Callback.</param>
67-
public bool GetWorkspaces(OnGetWorkspaces callback)
68-
{
69-
if(callback == null)
70-
throw new ArgumentNullException("callback");
45+
#endregion
7146

72-
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v2/rest/workspaces");
73-
if(connector == null)
74-
return false;
75-
76-
GetWorkspacesReq req = new GetWorkspacesReq();
77-
req.Callback = callback;
78-
req.OnResponse = OnGetWorkspacesResp;
79-
80-
return connector.Send(req);
81-
}
82-
83-
private class GetWorkspacesReq : RESTConnector.Request
84-
{
85-
public OnGetWorkspaces Callback { get; set; }
86-
}
87-
88-
private void OnGetWorkspacesResp(RESTConnector.Request req, RESTConnector.Response resp)
89-
{
90-
DataModels.Workspaces workspaces= new DataModels.Workspaces();
91-
if (resp.Success)
92-
{
93-
try
94-
{
95-
fsData data = null;
96-
fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
97-
if (!r.Succeeded)
98-
throw new WatsonException(r.FormattedMessages);
99-
100-
object obj = workspaces;
101-
r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
102-
if (!r.Succeeded)
103-
throw new WatsonException(r.FormattedMessages);
104-
}
105-
catch (Exception e)
106-
{
107-
Log.Error("Conversation", "GetWorkspaces Exception: {0}", e.ToString());
108-
resp.Success = false;
109-
}
110-
}
47+
#region Message
48+
/// <summary>
49+
/// The callback delegate for the Message() function.
50+
/// </summary>
51+
/// <param name="resp">The response object to a call to Message().</param>
52+
public delegate void OnMessage(MessageResponse resp, string customData);
11153

112-
if (((GetWorkspacesReq)req).Callback != null)
113-
((GetWorkspacesReq)req).Callback(resp.Success ? workspaces : null);
114-
}
115-
#endregion
116-
*/
117-
#region Message
118-
private const string SERVICE_MESSAGE = "/v1/workspaces";
119-
/// <summary>
120-
/// Message the specified workspaceId, input and callback.
121-
/// </summary>
122-
/// <param name="workspaceId">Workspace identifier.</param>
123-
/// <param name="input">Input.</param>
124-
/// <param name="callback">Callback.</param>
125-
public bool Message(string workspaceId, string input, OnMessage callback)
54+
/// <summary>
55+
/// Message the specified workspaceId, input and callback.
56+
/// </summary>
57+
/// <param name="workspaceID">Workspace identifier.</param>
58+
/// <param name="input">Input.</param>
59+
/// <param name="callback">Callback.</param>
60+
/// <param name="customData">Custom data.</param>
61+
public bool Message(OnMessage callback, string workspaceID, string input, string customData = default(string))
12662
{
127-
if(string.IsNullOrEmpty(workspaceId))
63+
if(string.IsNullOrEmpty(workspaceID))
12864
throw new ArgumentNullException("workspaceId");
12965
if(string.IsNullOrEmpty(input))
13066
throw new ArgumentNullException("input");
@@ -143,16 +79,95 @@ public bool Message(string workspaceId, string input, OnMessage callback)
14379
req.Headers["Content-Type"] = "application/json";
14480
req.Headers["Accept"] = "application/json";
14581
req.Parameters["version"] = Version.VERSION;
146-
req.Function = "/" + workspaceId + "/message";
82+
req.Function = "/" + workspaceID + "/message";
83+
req.Data = customData;
14784
req.Send = Encoding.UTF8.GetBytes(reqString);
14885
req.OnResponse = MessageResp;
14986

15087
return connector.Send(req);
15188
}
15289

90+
/// <summary>
91+
/// Message the specified workspaceId, input and callback.
92+
/// </summary>
93+
/// <param name="callback">Callback.</param>
94+
/// <param name="workspaceID">Workspace identifier.</param>
95+
/// <param name="messageRequest">Message request object.</param>
96+
/// <param name="customData">Custom data.</param>
97+
/// <returns></returns>
98+
public bool Message(OnMessage callback, string workspaceID, MessageRequest messageRequest, string customData = default(string))
99+
{
100+
if (string.IsNullOrEmpty(workspaceID))
101+
throw new ArgumentNullException("workspaceId");
102+
if(string.IsNullOrEmpty(messageRequest.input.text))
103+
throw new ArgumentNullException("messageRequest.input.text");
104+
if (callback == null)
105+
throw new ArgumentNullException("callback");
106+
107+
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
108+
if (connector == null)
109+
return false;
110+
111+
fsData data;
112+
sm_Serializer.TrySerialize(messageRequest.GetType(), messageRequest, out data).AssertSuccessWithoutWarnings();
113+
string reqString = fsJsonPrinter.CompressedJson(data);
114+
115+
MessageReq req = new MessageReq();
116+
req.Callback = callback;
117+
req.MessageRequest = messageRequest;
118+
req.Headers["Content-Type"] = "application/json";
119+
req.Headers["Accept"] = "application/json";
120+
req.Parameters["version"] = Version.VERSION;
121+
req.Function = "/" + workspaceID + "/message";
122+
req.Data = customData;
123+
req.Send = Encoding.UTF8.GetBytes(reqString);
124+
req.OnResponse = MessageResp;
125+
126+
return connector.Send(req);
127+
}
128+
129+
public bool Message(OnMessage callback, string workspaceID, string input, bool useAlternateIntents, string conversationID = default(string), string customData = default(string))
130+
{
131+
if (string.IsNullOrEmpty(workspaceID))
132+
throw new ArgumentNullException("workspaceId");
133+
if (string.IsNullOrEmpty(input))
134+
throw new ArgumentNullException("input");
135+
if (callback == null)
136+
throw new ArgumentNullException("callback");
137+
138+
MessageRequest messageRequest = new MessageRequest();
139+
messageRequest.inputText = input;
140+
messageRequest.alternate_intents = useAlternateIntents;
141+
if (conversationID != default(string))
142+
messageRequest.conversationID = conversationID;
143+
144+
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
145+
if (connector == null)
146+
return false;
147+
148+
fsData data;
149+
sm_Serializer.TrySerialize(messageRequest.GetType(), messageRequest, out data).AssertSuccessWithoutWarnings();
150+
string reqString = fsJsonPrinter.CompressedJson(data);
151+
152+
MessageReq req = new MessageReq();
153+
req.Callback = callback;
154+
req.MessageRequest = messageRequest;
155+
req.Headers["Content-Type"] = "application/json";
156+
req.Headers["Accept"] = "application/json";
157+
req.Parameters["version"] = Version.VERSION;
158+
req.Function = "/" + workspaceID + "/message";
159+
req.Data = customData;
160+
req.Send = Encoding.UTF8.GetBytes(reqString);
161+
req.OnResponse = MessageResp;
162+
163+
return connector.Send(req);
164+
}
165+
153166
private class MessageReq : RESTConnector.Request
154167
{
155168
public OnMessage Callback { get; set; }
169+
public MessageRequest MessageRequest { get; set; }
170+
public string Data { get; set; }
156171
}
157172

158173
private void MessageResp(RESTConnector.Request req, RESTConnector.Response resp)
@@ -180,7 +195,7 @@ private void MessageResp(RESTConnector.Request req, RESTConnector.Response resp)
180195
}
181196

182197
if (((MessageReq)req).Callback != null)
183-
((MessageReq)req).Callback(resp.Success ? response : null);
198+
((MessageReq)req).Callback(resp.Success ? response : null, ((MessageReq)req).Data);
184199
}
185200
#endregion
186201

@@ -231,7 +246,7 @@ public CheckServiceStatus(Conversation service, ServiceStatus callback)
231246
if (!string.IsNullOrEmpty(customServiceID))
232247
{
233248

234-
if (!m_Service.Message(customServiceID, "Ping", OnMessage))
249+
if (!m_Service.Message(OnMessage, customServiceID, "Ping", "Ping"))
235250
OnFailure("Failed to invoke Converse().");
236251
else
237252
m_ConversationCount += 1;
@@ -242,7 +257,7 @@ public CheckServiceStatus(Conversation service, ServiceStatus callback)
242257
}
243258
}
244259

245-
private void OnMessage(MessageResponse resp)
260+
private void OnMessage(MessageResponse resp, string customData)
246261
{
247262
if (m_ConversationCount > 0)
248263
{

0 commit comments

Comments
 (0)