diff --git a/CHANGELOG.md b/CHANGELOG.md
index 00d3293b2..2dd1b8b9c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
Change Log
==========
+## Version 0.11.0
+_2016_10_27_
+* New: Abstracted `Speech to Text` customization methods.
+
## Version 0.10.0
_2016_09_23_
@@ -7,7 +11,7 @@ _2016_09_23_
* Fix: `Touch Widget` improvmements.
* Fix: Disabled 3rd Party plugin warnings.
* Fix: Removed `Conversation` Message overload method that takes only input and conversationID.
-* Fix: Rewrote `Conversation` example script to show how to create MessageRequest object.
+* Fix: Rewrote `Conversation` example script to show how to create MessageRequest object.
## Version 0.9.0
_2016-08-26_
diff --git a/Examples/ServiceExamples/Scripts/ExampleConversation.cs b/Examples/ServiceExamples/Scripts/ExampleConversation.cs
index d6c0543dc..00c5cf156 100755
--- a/Examples/ServiceExamples/Scripts/ExampleConversation.cs
+++ b/Examples/ServiceExamples/Scripts/ExampleConversation.cs
@@ -25,7 +25,6 @@ public class ExampleConversation : MonoBehaviour
{
private Conversation m_Conversation = new Conversation();
private string m_WorkspaceID;
- private string m_ConversationID;
private bool m_UseAlternateIntents = true;
private string[] questionArray = { "can you turn up the AC", "can you turn on the wipers", "can you turn off the wipers", "can you turn down the ac", "can you unlock the door"};
@@ -57,8 +56,6 @@ private void OnMessageWithOnlyInput(MessageResponse resp, string customData)
foreach (string txt in resp.output.text)
Debug.Log("output: " + txt);
- m_ConversationID = resp.context.conversation_id;
-
string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
Debug.Log(string.Format("**********User: {0}", questionStr));
diff --git a/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs b/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs
old mode 100644
new mode 100755
index a1d38737a..83af8506f
--- a/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs
+++ b/Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs
@@ -17,6 +17,8 @@
using UnityEngine;
using IBM.Watson.DeveloperCloud.Services.SpeechToText.v1;
+using IBM.Watson.DeveloperCloud.Logging;
+#pragma warning disable 0414
public class ExampleSpeechToText : MonoBehaviour
{
@@ -24,23 +26,443 @@ public class ExampleSpeechToText : MonoBehaviour
private AudioClip m_AudioClip = new AudioClip();
private SpeechToText m_SpeechToText = new SpeechToText();
- void Start()
+ private string m_CreatedCustomizationID;
+ private string m_CreatedCorpusName = "unity-corpus";
+ private string m_CustomCorpusFilePath;
+
+ void Start()
{
- m_SpeechToText.Recognize(m_AudioClip, HandleOnRecognize);
+ //m_SpeechToText.Recognize(m_AudioClip, HandleOnRecognize);
+ LogSystem.InstallDefaultReactors();
+
+ m_CustomCorpusFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-corpus.txt";
+
+ // test GetModels and GetModel
+ //TestGetModels();
+
+ // test CreateSession
+ //TestCreateSession("en-US_BroadbandModel");
+
+ // test GetCustomizations
+ //TestGetCustomizations();
+
+ // test create, get and delete customizations
+ //TestCreateCustomization();
}
- void HandleOnRecognize (SpeechResultList result)
+ private void TestGetModels()
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to get models");
+ m_SpeechToText.GetModels(HandleGetModels);
+ }
+
+ private void TestGetModel(string modelID)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to get model {0}", modelID);
+ m_SpeechToText.GetModel(HandleGetModel, modelID);
+ }
+
+ private void TestGetCustomizations()
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to get customizations");
+ m_SpeechToText.GetCustomizations(HandleGetCustomizations);
+ }
+
+ private void TestCreateCustomization()
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting create customization");
+ m_SpeechToText.CreateCustomization(HandleCreateCustomization, "unity-test-customization", "en-US_BroadbandModel", "Testing customization unity");
+ }
+
+ private void TestDeleteCustomization(string customizationID)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to delete customization {0}", customizationID);
+ m_SpeechToText.DeleteCustomization(HandleDeleteCustomization, customizationID);
+ }
+
+ private void TestGetCustomization(string customizationID)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to get customization {0}", customizationID);
+ m_SpeechToText.GetCustomization(HandleGetCustomization, customizationID);
+ }
+
+ private void TestTrainCustomization(string customizationID)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to train customization {0}", customizationID);
+ m_SpeechToText.TrainCustomization(HandleTrainCustomization, customizationID);
+ }
+
+ private void TestUpgradeCustomization(string customizationID)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to upgrade customization {0}", customizationID);
+ m_SpeechToText.UpgradeCustomization(HandleUpgradeCustomization, customizationID);
+ }
+
+ private void TestResetCustomization(string customizationID)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to reset customization {0}", customizationID);
+ m_SpeechToText.ResetCustomization(HandleResetCustomization, customizationID);
+ }
+
+ private void TestGetCustomCorpora(string customizationID)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to get custom corpora for {0}", customizationID);
+ m_SpeechToText.GetCustomCorpora(HandleGetCustomCorpora, customizationID);
+ }
+
+ private void TestDeleteCustomCorpus(string customizationID, string corpusName)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to delete custom corpus {1} in customization {0}", customizationID, corpusName);
+ m_SpeechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, customizationID, corpusName);
+ }
+
+ private void TestAddCustomCorpus(string customizationID, string corpusName, bool allowOverwrite, string trainingDataPath)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to add custom corpus {1} in customization {0}", customizationID, corpusName);
+ m_SpeechToText.AddCustomCorpus(HandleAddCustomCorpus, customizationID, corpusName, allowOverwrite, trainingDataPath);
+ }
+
+ private void TestGetCustomWords()
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to get custom words.");
+ m_SpeechToText.GetCustomWords(HandleGetCustomWords, m_CreatedCustomizationID);
+ }
+
+ private void TestAddCustomWordsPath(string customizationID, string wordsJsonPath)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words json path {1}", customizationID, wordsJsonPath);
+ m_SpeechToText.AddCustomWords(HandleAddCustomWords, customizationID, wordsJsonPath);
+ }
+
+ private void TestAddCustomWordsWordsObject(string customizationID, Words words)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words object", customizationID);
+ m_SpeechToText.AddCustomWords(HandleAddCustomWords, customizationID, words);
+ }
+
+ private void TestDeleteCustomWord(string customizationID, string word)
+ {
+ Log.Debug("ExampleSpeechToText", "Attempting to delete custom word {1} in customization {0}", customizationID, word);
+ m_SpeechToText.DeleteCustomWord(HandleDeleteCustomWord, customizationID, word);
+ }
+
+ private void TestGetCustomWord(string customizationID, string word)
{
- if (result != null && result.Results.Length > 0)
+ Log.Debug("ExampleSpeechToText", "Attempting to get custom word {1} in customization {0}", customizationID, word);
+ m_SpeechToText.GetCustomWord(HandleGetCustomWord, customizationID, word);
+ }
+
+
+
+ private void HandleGetModels(Model[] models)
+ {
+ if (models != null)
+ {
+ if (models != null)
+ {
+ if (models.Length == 0)
+ {
+ Log.Warning("ExampleSpeedchToText", "There are no custom models!");
+ }
+ else
+ {
+ foreach (Model model in models)
+ {
+ Log.Debug("ExampleSpeechToText", "Model: {0}", model.name);
+ }
+
+ TestGetModel((models[Random.Range(0, models.Length - 1)] as Model).name);
+ }
+ }
+ }
+ else
+ {
+ Log.Warning("ExampleSpeechToText", "Failed to get models!");
+ }
+ }
+
+ private void HandleGetModel(Model model)
+ {
+ if(model != null)
+ {
+ Log.Debug("ExampleSpeechToText", "Model - name: {0} | description: {1} | language:{2} | rate: {3} | sessions: {4} | url: {5} | customLanguageModel: {6}",
+ model.name, model.description, model.language, model.rate, model.sessions, model.url, model.supported_features.custom_language_model);
+ }
+ else
+ {
+ Log.Warning("ExampleSpeechToText", "Failed to get model!");
+ }
+ }
+
+ private void HandleOnRecognize (SpeechRecognitionEvent result)
+ {
+ if (result != null && result.results.Length > 0)
{
- foreach( var res in result.Results )
+ foreach( var res in result.results )
{
- foreach( var alt in res.Alternatives )
+ foreach( var alt in res.alternatives )
{
- string text = alt.Transcript;
- Debug.Log(string.Format( "{0} ({1}, {2:0.00})\n", text, res.Final ? "Final" : "Interim", alt.Confidence));
+ string text = alt.transcript;
+ Log.Debug("ExampleSpeechToText", string.Format( "{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence));
}
}
}
}
-}
+
+ private void HandleGetCustomizations(Customizations customizations, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (customizations != null)
+ {
+ if(customizations.customizations.Length > 0)
+ {
+ foreach (Customization customization in customizations.customizations)
+ Log.Debug("ExampleSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status);
+
+ Log.Debug("ExampleSpeechToText", "GetCustomizations() succeeded!");
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "There are no customizations!");
+ }
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to get customizations!");
+ }
+ }
+
+ private void HandleCreateCustomization(CustomizationID customizationID, string customData)
+ {
+ if(customizationID != null)
+ {
+ Log.Debug("ExampleSpeechToText", "Customization created: {0}", customizationID.customization_id);
+ Log.Debug("ExampleSpeechToText", "CreateCustomization() succeeded!");
+
+ m_CreatedCustomizationID = customizationID.customization_id;
+ TestGetCustomization(m_CreatedCustomizationID);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to create customization!");
+ }
+ }
+
+ private void HandleDeleteCustomization(bool success, string customData)
+ {
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "Deleted customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("ExampleSpeechToText", "DeletedCustomization() succeeded!");
+ m_CreatedCustomizationID = default(string);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to delete customization!");
+ }
+ }
+
+ private void HandleGetCustomization(Customization customization, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if(customization != null)
+ {
+ Log.Debug("ExampleSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status);
+ Log.Debug("ExampleSpeechToText", "GetCustomization() succeeded!");
+
+ // test add custom corpora
+ //TestAddCustomCorpus(m_CreatedCustomizationID, m_CreatedCorpusName, true, m_CustomCorpusFilePath);
+ TestDeleteCustomization(m_CreatedCustomizationID);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to get customization {0}!", m_CreatedCustomizationID);
+ }
+ }
+
+ private void HandleTrainCustomization(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "Train customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("ExampleSpeechToText", "TrainCustomization() succeeded!");
+
+ TestResetCustomization(m_CreatedCustomizationID);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to train customization!");
+ }
+ }
+
+ private void HandleUpgradeCustomization(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "Upgrade customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("ExampleSpeechToText", "UpgradeCustomization() succeeded!");
+
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to upgrade customization!");
+ }
+ }
+
+ private void HandleResetCustomization(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "Reset customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("ExampleSpeechToText", "ResetCustomization() succeeded!");
+
+ // test delete custom corpus
+ TestDeleteCustomCorpus(m_CreatedCustomizationID, m_CreatedCorpusName);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to reset customization!");
+ }
+ }
+
+ private void HandleGetCustomCorpora(Corpora corpora, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "CustomData: {0}", customData);
+
+ if(corpora != null)
+ {
+ if(corpora.corpora.Length > 0)
+ {
+ foreach (Corpus corpus in corpora.corpora)
+ Log.Debug("ExampleSpeechToText", "Corpus - name: {0} | total_words: {1} | out_of_vocabulary_words: {2} | staus: {3}",
+ corpus.name, corpus.total_words, corpus.out_of_vocabulary_words, corpus.status);
+
+ //TestUpgradeCustomization(m_CreatedCustomizationID);
+ TestTrainCustomization(m_CreatedCustomizationID);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "There are no custom corpora!");
+ }
+
+ Log.Debug("ExampleSpeechToText", "GetCustomCorpora() succeeded!");
+ TestDeleteCustomization(m_CreatedCustomizationID);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to get custom corpora!");
+ }
+ }
+
+ private void HandleDeleteCustomCorpus(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "DeleteCustomCorpus() succeeded!");
+
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to delete custom corpus!");
+ }
+ }
+
+ private void HandleAddCustomCorpus(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "AddCustomCorpus() succeeded!");
+
+ // test get custom corpora
+ TestGetCustomCorpora(m_CreatedCustomizationID);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to delete custom corpus!");
+ }
+ }
+
+ private void HandleGetCustomWords(WordsList wordList, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if(wordList != null)
+ {
+ if (wordList.words != null && wordList.words.Length > 0)
+ {
+ foreach (WordData word in wordList.words)
+ Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as);
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "No custom words found!");
+ }
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to get custom words!");
+ }
+ }
+
+ private void HandleAddCustomWords(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "AddCustomWOrds() succeeded!");
+
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to add custom words!");
+ }
+ }
+
+ private void HandleDeleteCustomWord(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("ExampleSpeechToText", "DeleteCustomWord() succeeded!");
+
+ }
+ else
+ {
+ Log.Debug("ExampleSpeechToText", "Failed to delete custom word!");
+ }
+ }
+
+ private void HandleGetCustomWord(WordData word, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
+
+ if(word != null)
+ Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as);
+ }
+}
\ No newline at end of file
diff --git a/Examples/ServiceExamples/ServiceExamples.unity b/Examples/ServiceExamples/ServiceExamples.unity
index ad85f0afb..2b1a02976 100755
--- a/Examples/ServiceExamples/ServiceExamples.unity
+++ b/Examples/ServiceExamples/ServiceExamples.unity
@@ -352,7 +352,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
- m_IsActive: 1
+ m_IsActive: 0
--- !u!114 &859102723
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -472,7 +472,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
- m_IsActive: 0
+ m_IsActive: 1
--- !u!114 &1160237479
MonoBehaviour:
m_ObjectHideFlags: 0
diff --git a/Examples/ServiceExamples/TestData/test-stt-corpus.txt b/Examples/ServiceExamples/TestData/test-stt-corpus.txt
new file mode 100644
index 000000000..d3ea99b59
--- /dev/null
+++ b/Examples/ServiceExamples/TestData/test-stt-corpus.txt
@@ -0,0 +1,58 @@
+Adds a single corpus text file of new training data to the custom language model.
+Use multiple requests to submit multiple corpus text files.
+Only the owner of a custom model can use this method to add a corpus to the model.
+
+Submit a plain text file that contains sample sentences from the domain of interest to enable the service to extract words in context.
+The more sentences you add that represent the context in which speakers use words from the domain, the better the service's recognition accuracy.
+Adding a corpus does not affect the custom model until you train the model for the new data by using the Train a custom model method.
+
+Use the following guidelines to prepare a corpus text file:
+
+Provide a plain text file that is encoded in UTF-8 if it contains non-ASCII characters.
+The service assumes UTF-8 encoding if it encounters such characters.
+
+Include each sentence of the corpus on its own line, terminating each line with a carriage return.
+Including multiple sentences on the same line can degrade accuracy.
+
+Use consistent capitalization for words in the corpus.
+The words resource is case-sensitive; mix upper- and lowercase letters and use capitalization only when intended.
+
+Beware of typographical errors.
+The service assumes that typos are new words; unless you correct them before training the model, the service adds them to the model's vocabulary.
+
+The service automatically does the following:
+
+Converts numbers to their equivalent words.
+For example, 500 becomes five hundred, and 0.15 becomes zero point fifteen.
+
+Removes the following punctuation and special characters:
+
+! @ # $ % ^ & * - + = ~ _ . , ; : ( ) < > [ ] { }
+
+Ignores phrases enclosed in ( ) (parentheses), < > (angle brackets), [ ] (square brackets), and { } (curly braces).
+
+Converts tokens that include certain symbols to meaningful strings.
+For example, the service
+
+Converts a $ (dollar sign) followed by a number to its string representation.
+For example, $100 becomes one hundred dollars.
+
+Converts a % (percent sign) preceded by a number to its string representation.
+For example, 100% becomes one hundred percent.
+
+This list is not exhaustive; the service makes similar adjustments for other characters as needed.
+
+The call returns an HTTP 201 response code if the corpus is valid. It then asynchronously pre-processes the contents of the corpus and automatically extracts new words that it finds.
+This can take on the order of a minute or two to complete depending on the total number of words and the number of new words in the corpus, as well as the current load on the service.
+You cannot submit requests to add additional corpora or words to the custom model, or to train the model, until the service's analysis of the corpus for the current request completes.
+Use the List corpora method to check the status of the analysis.
+
+The service auto-populates the model's words resource with any word that is not found in its base vocabulary; these are referred to as out-of-vocabulary (OOV) words.
+You can use the List custom words method to examine the words resource, using other words method to eliminate typos and modify how words are pronounced as needed.
+
+To add a corpus file that has the same name as an existing corpus, set the allow_overwrite query parameter to true; otherwise, the request fails.
+Overwriting an existing corpus causes the service to process the corpus text file and extract OOV words anew.
+Before doing so, it removes any OOV words associated with the existing corpus from the model's words resource unless they were also added by another corpus or they have been modified in some way with the Add custom words or Add a custom word method.
+
+The service limits the overall amount of data that you can add to a custom model to a maximum of 10 million total words from all corpora combined.
+Also, you can add no more than 30 thousand new words to a model; this includes words that the service extracts from corpora and words that you add directly.
\ No newline at end of file
diff --git a/Examples/ServiceExamples/TestData/test-stt-corpus.txt.meta b/Examples/ServiceExamples/TestData/test-stt-corpus.txt.meta
new file mode 100755
index 000000000..b9d4c9893
--- /dev/null
+++ b/Examples/ServiceExamples/TestData/test-stt-corpus.txt.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 91ef033de03807e4d8649447da53809a
+timeCreated: 1475787453
+licenseType: Pro
+TextScriptImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Examples/ServiceExamples/TestData/test-stt-words.json b/Examples/ServiceExamples/TestData/test-stt-words.json
new file mode 100644
index 000000000..26008fb40
--- /dev/null
+++ b/Examples/ServiceExamples/TestData/test-stt-words.json
@@ -0,0 +1,25 @@
+{
+ "words": [
+ {
+ "word": "watson",
+ "sounds_like": [
+ "wat son"
+ ],
+ "display_as": "Watson"
+ },
+ {
+ "word": "unity",
+ "sounds_like": [
+ "you ni tee"
+ ],
+ "display_as": "Unity"
+ },
+ {
+ "word": "sdk",
+ "sounds_like": [
+ "S.D.K."
+ ],
+ "display_as": "SDK"
+ }
+ ]
+}
diff --git a/Examples/ServiceExamples/TestData/test-stt-words.json.meta b/Examples/ServiceExamples/TestData/test-stt-words.json.meta
new file mode 100644
index 000000000..296fe082a
--- /dev/null
+++ b/Examples/ServiceExamples/TestData/test-stt-words.json.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: cb094b0ede792384cbf9aa9dac10ec83
+timeCreated: 1475858824
+licenseType: Pro
+TextScriptImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Scripts/Connection/RESTConnector.cs b/Scripts/Connection/RESTConnector.cs
index 2098767fe..9de47d8ae 100755
--- a/Scripts/Connection/RESTConnector.cs
+++ b/Scripts/Connection/RESTConnector.cs
@@ -479,7 +479,7 @@ private IEnumerator ProcessRequestQueue()
{
resp.Success = true;
resp.Data = www.bytes;
- }
+ }
else
{
resp.Success = false;
diff --git a/Scripts/Services/SpeechToText/DataModels.cs b/Scripts/Services/SpeechToText/DataModels.cs
old mode 100644
new mode 100755
index 61ae17180..a99bed71c
--- a/Scripts/Services/SpeechToText/DataModels.cs
+++ b/Scripts/Services/SpeechToText/DataModels.cs
@@ -21,139 +21,660 @@
namespace IBM.Watson.DeveloperCloud.Services.SpeechToText.v1
{
- ///
- /// This data class holds the data for a given speech model.
- ///
- [fsObject]
- public class SpeechModel
- {
- ///
- /// The name of the speech model.
- ///
- public string Name { get; set; }
- ///
- /// The optimal sample rate for this model.
- ///
- public long Rate { get; set; }
- ///
- /// The language ID for this model. (e.g. en)
- ///
- public string Language { get; set; }
- ///
- /// A description for this model.
- ///
- public string Description { get; set; }
- ///
- /// The URL for this model.
- ///
- public string URL { get; set; }
- };
- ///
- /// This data class holds the confidence value for a given recognized word.
- ///
- [fsObject]
- public class WordConfidence
- {
- ///
- /// The word as a string.
- ///
- public string Word { get; set; }
- ///
- /// The confidence value for this word.
- ///
- public double Confidence { get; set; }
- };
- ///
- /// This data class holds the start and stop times for a word.
- ///
- [fsObject]
- public class TimeStamp
- {
- ///
- /// The word.
- ///
- public string Word { get; set; }
- ///
- /// The start time.
- ///
- public double Start { get; set; }
- ///
- /// The stop time.
- ///
- public double End { get; set; }
- };
- ///
- /// This data class holds the actual transcript for the text generated from speech audio data.
- ///
- [fsObject]
- public class SpeechAlt
- {
- ///
- /// The transcript of what was understood.
- ///
- public string Transcript { get; set; }
- ///
- /// The confidence in this transcript of the audio data.
- ///
- public double Confidence { get; set; }
- ///
- /// A optional array of timestamps objects.
- ///
- public TimeStamp[] Timestamps { get; set; }
- ///
- /// A option array of word confidence values.
- ///
- public WordConfidence[] WordConfidence { get; set; }
- };
- ///
- /// A Result object that is returned by the Recognize() method.
- ///
- [fsObject]
- public class SpeechResult
- {
- ///
- /// If true, then this is the final result and no more results will be sent for the given audio data.
- ///
- public bool Final { get; set; }
- ///
- /// A array of alternatives speech to text results, this is controlled by the MaxAlternatives property.
- ///
- public SpeechAlt[] Alternatives { get; set; }
- };
- ///
- /// This data class holds a list of Result objects returned by the Recognize() method.
- ///
- [fsObject]
- public class SpeechResultList
- {
- ///
- /// The array of Result objects.
- ///
- public SpeechResult[] Results { get; set; }
-
- ///
- public SpeechResultList(SpeechResult[] results)
- {
- Results = results;
- }
-
- ///
- /// Check if our result list has atleast one valid result.
- ///
- /// Returns true if a result is found.
- public bool HasResult()
- {
- return Results != null && Results.Length > 0
- && Results[0].Alternatives != null && Results[0].Alternatives.Length > 0;
- }
-
- ///
- /// Returns true if we have a final result.
- ///
- ///
- public bool HasFinalResult()
- {
- return HasResult() && Results[0].Final;
- }
- };
+ #region Models
+ ///
+ /// This data class holds multiple speech models.
+ ///
+ [fsObject]
+ public class ModelSet
+ {
+ ///
+ /// Information about each available model.
+ ///
+ public Model[] models { get; set; }
+ }
+ ///
+ /// This data class holds the data for a given speech model.
+ ///
+ [fsObject]
+ public class Model
+ {
+ ///
+ /// The name of the speech model.
+ ///
+ public string name { get; set; }
+ ///
+ /// The language ID for this model. (e.g. en)
+ ///
+ public string language { get; set; }
+ ///
+ /// The optimal sample rate for this model.
+ ///
+ public long rate { get; set; }
+ ///
+ /// The URL for this model.
+ ///
+ public string url { get; set; }
+ ///
+ /// Information about each available model.
+ ///
+ public string sessions { get; set; }
+ ///
+ /// Describes the additional service features supported with the model.
+ ///
+ public SupportedFeatures supported_features { get; set; }
+ ///
+ /// A description for this model.
+ ///
+ public string description { get; set; }
+ };
+
+ ///
+ /// This data class holds all supported features.
+ ///
+ [fsObject]
+ public class SupportedFeatures
+ {
+ ///
+ /// Describes the additional service features supported with the model.
+ ///
+ public bool custom_language_model { get; set; }
+ }
+ #endregion
+
+ #region Sessions and Sessionless
+ ///
+ /// This data class holds the Session data.
+ ///
+ [fsObject]
+ public class Session
+ {
+ ///
+ /// Describes the additional service features supported with the model.
+ ///
+ public string session_id { get; set; }
+ ///
+ /// Describes the additional service features supported with the model.
+ ///
+ public string new_session_uri { get; set; }
+ ///
+ /// URI for REST recognition requests.
+ ///
+ public string recognize { get; set; }
+ ///
+ /// URI for REST results observers.
+ ///
+ public string observe_result { get; set; }
+ ///
+ /// URI for WebSocket recognition requests. Needed only for working with the WebSocket interface.
+ ///
+ public string recognizeWS { get; set; }
+ }
+
+ ///
+ /// This data object contains data for the speechRecognitionEvent.
+ ///
+ [fsObject]
+ public class SpeechRecognitionEvent
+ {
+ ///
+ /// The results array consists of zero or more final results followed by zero or one interim result. The final results are guaranteed not to change; the interim result may be replaced by zero or more final results (followed by zero or one interim result). The service periodically sends updates to the result list, with the result_index set to the lowest index in the array that has changed.
+ ///
+ public SpeechRecognitionResult[] results { get; set; }
+ ///
+ /// An index that indicates the change point in the results array.
+ ///
+ public int result_index { get; set; }
+ ///
+ /// An array of warning messages about invalid query parameters or JSON fields included with the request. Each warning includes a descriptive message and a list of invalid argument strings. For example, a message such as "Unknown arguments:" or "Unknown url query arguments:" followed by a list of the form "invalid_arg_1, invalid_arg_2." The request succeeds despite the warnings.
+ ///
+ public string[] warnings { get; set; }
+
+ ///
+ public SpeechRecognitionEvent(SpeechRecognitionResult[] _results)
+ {
+ results = _results;
+ }
+
+ ///
+ /// Check if our result list has atleast one valid result.
+ ///
+ /// Returns true if a result is found.
+ public bool HasResult()
+ {
+ return results != null && results.Length > 0
+ && results[0].alternatives != null && results[0].alternatives.Length > 0;
+ }
+
+ ///
+ /// Returns true if we have a final result.
+ ///
+ ///
+ public bool HasFinalResult()
+ {
+ return HasResult() && results[0].final;
+ }
+ }
+
+ ///
+ /// The speech recognition result.
+ ///
+ [fsObject]
+ public class SpeechRecognitionResult
+ {
+ ///
+ /// If true, the result for this utterance is not updated further.
+ ///
+ public bool final { get; set; }
+ ///
+ /// Array of alternative transcripts.
+ ///
+ public SpeechRecognitionAlternative[] alternatives { get; set; }
+ ///
+ /// Dictionary (or associative array) whose keys are the strings specified for keywords if both that parameter and keywords_threshold are specified. A keyword for which no matches are found is omitted from the array.
+ ///
+ public KeywordResults keywords_result { get; set; }
+ ///
+ /// Array of word alternative hypotheses found for words of the input audio if word_alternatives_threshold is not null.
+ ///
+ public WordAlternativeResults word_alternatives { get; set; }
+ }
+
+ ///
+ /// The alternatives.
+ ///
+ [fsObject]
+ public class SpeechRecognitionAlternative
+ {
+ ///
+ /// Transcription of the audio.
+ ///
+ public string transcript { get; set; }
+
+ ///
+ /// Confidence score of the transcript in the range of 0 to 1. Available only for the best alternative and only in results marked as final.
+ ///
+ public double confidence { get; set; }
+ ///
+ /// Time alignments for each word from transcript as a list of lists. Each inner list consists of three elements: the word followed by its start and end time in seconds. Example: [["hello",0.0,1.2],["world",1.2,2.5]]. Available only for the best alternative.
+ ///
+ public string[] timestamps { get; set; }
+ ///
+ /// Confidence score for each word of the transcript as a list of lists. Each inner list consists of two elements: the word and its confidence score in the range of 0 to 1. Example: [["hello",0.95],["world",0.866]]. Available only for the best alternative and only in results marked as final.
+ ///
+ public string[] word_confidence { get; set; }
+ ///
+ /// A optional array of timestamps objects.
+ ///
+ public TimeStamp[] Timestamps { get; set; }
+ ///
+ /// A option array of word confidence values.
+ ///
+ public WordConfidence[] WordConfidence { get; set; }
+ }
+
+ ///
+ /// The Keword Result
+ ///
+ [fsObject]
+ public class KeywordResults
+ {
+ ///
+ /// List of each keyword entered via the keywords parameter and, for each keyword, an array of KeywordResult objects that provides information about its occurrences in the input audio. The keys of the list are the actual keyword strings. A keyword for which no matches are spotted in the input is omitted from the array.
+ ///
+ public KeywordResult[] keyword { get; set; }
+ }
+
+ ///
+ /// This class holds a Word Alternative Result.
+ ///
+ [fsObject]
+ public class WordAlternativeResults
+ {
+ ///
+ /// Specified keyword normalized to the spoken phrase that matched in the audio input.
+ ///
+ public double start_time { get; set; }
+ ///
+ /// Specified keyword normalized to the spoken phrase that matched in the audio input.
+ ///
+ public double end_time { get; set; }
+ ///
+ /// Specified keyword normalized to the spoken phrase that matched in the audio input.
+ ///
+ public WordAlternativeResult[] alternatives { get; set; }
+ }
+
+ ///
+ /// This class holds a Keyword Result.
+ ///
+ [fsObject]
+ public class KeywordResult
+ {
+ ///
+ /// Specified keyword normalized to the spoken phrase that matched in the audio input.
+ ///
+ public string normalized_text { get; set; }
+ ///
+ /// Start time in seconds of the keyword match.
+ ///
+ public double start_time { get; set; }
+ ///
+ /// End time in seconds of the keyword match.
+ ///
+ public double end_time { get; set; }
+ ///
+ /// Confidence score of the keyword match in the range of 0 to 1.
+ ///
+ public double confidence { get; set; }
+ }
+
+ ///
+ /// This data class holds a Word Alternative Result.
+ ///
+ [fsObject]
+ public class WordAlternativeResult
+ {
+ ///
+ /// Confidence score of the word alternative hypothesis.
+ ///
+ public double confidence { get; set; }
+ ///
+ /// Word alternative hypothesis for a word from the input audio.
+ ///
+ public string word { get; set; }
+ }
+
+ ///
+ /// This data class holds the sesion data.
+ ///
+ [fsObject]
+ public class RecognizeStatus
+ {
+ ///
+ /// Description of the state and possible actions for the current session
+ ///
+ public SessionStatus session { get; set; }
+ }
+
+ ///
+ /// This data class holds the description of teh state and possbile actions for the current session.
+ ///
+ [fsObject]
+ public class SessionStatus
+ {
+ ///
+ /// State of the session. The state must be initialized to perform a new recognition request on the session.
+ ///
+ public string state { get; set; }
+ ///
+ /// URI for information about the model that is used with the session.
+ ///
+ public string model { get; set; }
+ ///
+ /// URI for REST recognition requests.
+ ///
+ public string recognize { get; set; }
+ ///
+ /// URI for REST results observers.
+ ///
+ public string observe_result { get; set; }
+ ///
+ /// URI for WebSocket recognition requests. Needed only for working with the WebSocket interface.
+ ///
+ public string recognizeWS { get; set; }
+ }
+
+ ///
+ /// This data class holds the confidence value for a given recognized word.
+ ///
+ [fsObject]
+ public class WordConfidence
+ {
+ ///
+ /// The word as a string.
+ ///
+ public string Word { get; set; }
+ ///
+ /// The confidence value for this word.
+ ///
+ public double Confidence { get; set; }
+ };
+ ///
+ /// This data class holds the start and stop times for a word.
+ ///
+ [fsObject]
+ public class TimeStamp
+ {
+ ///
+ /// The word.
+ ///
+ public string Word { get; set; }
+ ///
+ /// The start time.
+ ///
+ public double Start { get; set; }
+ ///
+ /// The stop time.
+ ///
+ public double End { get; set; }
+ };
+ #endregion
+
+ #region Asynchronous
+ ///
+ /// This data class contains information about the register callback status.
+ ///
+ public class RegisterStatus
+ {
+ ///
+ /// The current status of the job: created if the callback URL was successfully white-listed as a result of the call or already created if the URL was already white-listed.
+ ///
+ public string status { get; set; }
+ ///
+ /// The callback URL that is successfully registered
+ ///
+ public string url { get; set; }
+ }
+
+ ///
+ /// This data class contains information about the Jobs
+ ///
+ public class JobsStatusList
+ {
+ ///
+ /// The current status of the job: created if the callback URL was successfully white-listed as a result of the call or already created if the URL was already white-listed.
+ ///
+ public JobStatus[] recognitions { get; set; }
+ }
+
+ ///
+ /// This data class contains information about the job status.
+ ///
+ public class JobStatus
+ {
+ ///
+ /// The ID of the job.
+ ///
+ public string id { get; set; }
+ ///
+ /// The date and time in Coordinated Universal Time (UTC) at which the job was created. The value is provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD).
+ ///
+ public string created { get; set; }
+ ///
+ /// The date and time in Coordinated Universal Time (UTC) at which the job was last updated by the service. The value is provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD).
+ ///
+ public string updated { get; set; }
+ ///
+ /// The current status of the job. waiting: The service is preparing the job for processing; the service always returns this status when the job is initially created or when it is waiting for capacity to process the job. processing: The service is actively processing the job. completed: The service has finished processing the job; if the job specified a callback URL and the event recognitions.completed_with_results, the service sent the results with the callback notification; otherwise, use the GET /v1/recognitions/{id} method to retrieve the results. failed: The job failed.
+ ///
+ public string status { get; set; }
+ ///
+ /// The user token associated with a job that was created with a callback URL and a user token.
+ ///
+ public string user_token { get; set; }
+ }
+
+ ///
+ /// This data class contains information about a newly created recognition job.
+ ///
+ public class JobStatusNew
+ {
+ ///
+ /// The date and time in Coordinated Universal Time (UTC) at which the job was created. The value is provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD).
+ ///
+ public string created { get; set; }
+ ///
+ /// The ID of the job.
+ ///
+ public string id { get; set; }
+ ///
+ /// The URL to use to request information about the job with the GET /v1/recognitions/{id} method.
+ ///
+ public string url { get; set; }
+ ///
+ /// The current status of the job. waiting: The service is preparing the job for processing; the service always returns this status when the job is initially created or when it is waiting for capacity to process the job. processing: The service is actively processing the job. completed: The service has finished processing the job; if the job specified a callback URL and the event recognitions.completed_with_results, the service sent the results with the callback notification; otherwise, use the GET /v1/recognitions/{id} method to retrieve the results. failed: The job failed.
+ ///
+ public string status { get; set; }
+ }
+ #endregion
+
+ #region Custom Models
+ ///
+ /// This data class contains information about the speech to text model customizations.
+ ///
+ public class Customizations
+ {
+ ///
+ /// Information about each available custom model. The array is empty if the user owns no custom models (if no language is specified) or owns no custom models for the specified language.
+ ///
+ public Customization[] customizations { get; set; }
+ }
+
+ ///
+ /// This data class contains information about the Speech to Text model customizations.
+ ///
+ public class Customization
+ {
+ ///
+ /// The GUID of the custom language model.
+ ///
+ public string customization_id { get; set; }
+ ///
+ /// The date and time in Coordinated Universal Time (UTC) at which the custom language model was created. The value is provided in full ISO 8601 format (YYYY-MM-DDThh:mm:ss.sTZD).
+ ///
+ public string created { get; set; }
+ ///
+ /// The language of the custom language model. Currently, only en-US is supported.
+ ///
+ public string language { get; set; }
+ ///
+ /// The GUID of the service credentials for the owner of the custom language model.
+ ///
+ public string owner { get; set; }
+ ///
+ /// The name of the custom language model.
+ ///
+ public string name { get; set; }
+ ///
+ /// The description of the custom language model.
+ ///
+ public string description { get; set; }
+ ///
+ /// The name of the base language model for which the custom language model was created. = ['en-US_BroadbandModel', 'en-US_NarrowbandModel'].
+ ///
+ public string base_model_name { get; set; }
+ ///
+ /// The current status of the custom language model: pending indicates that the model was created but is waiting either for training data to be added or for the service to finish analyzing added data. ready indicates that the model contains data and is ready to be trained. training indicates that the model is currently being trained. For this beta release, the status field continues to be ready while the model is being trained; the field does not currently report a status of training. available indicates that the model is trained and ready to use. failed indicates that training of the model failed. = ['pending', 'ready', 'training', 'available', 'failed'].
+ ///
+ public string status { get; set; }
+ ///
+ /// A percentage that indicates the progress of the model's current training. A value of 100 means that the model is fully trained. For this beta release, the progress field does not reflect the current progress of the training; the field changes from 0 to 100 when training is complete.
+ ///
+ public int progress { get; set; }
+ ///
+ /// If the request included unknown query parameters, the following message: Unexpected query parameter(s) ['parameters'] detected, where parameters is a list that includes a quoted string for each unknown parameter.
+ ///
+ public string warnings { get; set; }
+ }
+
+ ///
+ /// This data class contains information about the language model customization identifier.
+ ///
+ public class CustomizationID
+ {
+ ///
+ /// The GUID of the new custom language model.
+ ///
+ public string customization_id { get; set; }
+ }
+
+ ///
+ /// A data object that contains data to create a new empty custom language mode3l.
+ ///
+ [fsObject]
+ public class CustomLanguage
+ {
+ ///
+ /// Name of the new custom language model.
+ ///
+ public string name { get; set; }
+ ///
+ /// The base model name - Currently only en-US_BroadbandModel is supported.
+ ///
+ public string base_model_name { get; set; }
+ ///
+ /// Description of the new custom voice model.
+ ///
+ public string description { get; set; }
+ }
+
+ ///
+ /// The type of words from the custom model's words resource on which to train the model: all (the default) trains the model on all new words, regardless of whether they were extracted from corpora or were added or modified by the user. user trains the model only on new words that were added or modified by the user; the model is not trained on new words extracted from corpora.
+ ///
+ public class WordTypeToAdd
+ {
+ ///
+ /// All word types.
+ ///
+ public const string ALL = "all";
+ ///
+ /// User word types.
+ ///
+ public const string USER = "user";
+ }
+ #endregion
+
+ #region Custom Corpora
+ ///
+ /// This data class contains information about multiple custom corpora.
+ ///
+ public class Corpora
+ {
+ ///
+ /// Information about corpora of the custom model. The array is empty if the custom model has no corpora.
+ ///
+ public Corpus[] corpora { get; set; }
+ }
+
+ ///
+ /// This data class contains information about the custom corpus.
+ ///
+ public class Corpus
+ {
+ ///
+ /// The name of the corpus.
+ ///
+ public string name { get; set; }
+ ///
+ /// The total number of words in the corpus. The value is 0 while the corpus is being processed.
+ ///
+ public int total_words { get; set; }
+ ///
+ /// The number of OOV words in the corpus. The value is 0 while the corpus is being processed.
+ ///
+ public int out_of_vocabulary_words { get; set; }
+ ///
+ /// The status of the corpus: analyzed indicates that the service has successfully analyzed the corpus; the custom model can be trained with data from the corpus. being_processed indicates that the service is still analyzing the corpus; the service cannot accept requests to add new corpora or words, or to train the custom model. undetermined indicates that the service encountered an error while processing the corpus. = ['analyzed', 'being_processed', 'undetermined']
+ ///
+ public string status { get; set; }
+ ///
+ /// If the status of the corpus is undetermined, the following message: Analysis of corpus 'name' failed. Please try adding the corpus again by setting the 'allow_overwrite' flag to 'true'.
+ ///
+ public string error { get; set; }
+ }
+ #endregion
+
+ #region Custom Words
+ ///
+ /// This data class contains information about multiple custom words.
+ ///
+ [fsObject]
+ public class WordsList
+ {
+ ///
+ /// Information about each word in the custom model's words resource. The array is empty if the custom model has no words.
+ ///
+ public WordData[] words { get; set; }
+ }
+
+ ///
+ /// This data class contains information about the custom word data.
+ ///
+ [fsObject]
+ public class WordData
+ {
+ ///
+ /// A custom word from the custom model. The spelling of the word is used to train the model.
+ ///
+ public string word { get; set; }
+ ///
+ /// An array of pronunciations for the custom word. The array can include the sounds-like pronunciation automatically generated by the service if none is provided for the word; the service adds this pronunciation when it finishes pre-processing the word.
+ ///
+ public string[] sounds_like { get; set; }
+ ///
+ /// The spelling of the custom word that the service uses to display the word in a transcript. The field contains an empty string if no display-as value is provided for the word, in which case the word is displayed as it is spelled.
+ ///
+ public string display_as { get; set; }
+ ///
+ /// An array of sources that describes how the word was added to the custom model's words resource. For OOV words added from a corpus, includes the name of the corpus; if the word was added by multiple corpora, the names of all corpora are listed. If the word was modified or added by the user directly, the field includes the string user.
+ ///
+ public string[] source { get; set; }
+ ///
+ /// If the service discovered a problem with the custom word's definition that you need to correct, a message that describes the problem, for example: Numbers are not allowed in sounds-like. You must correct the error before you can train the model.
+ ///
+ public string error { get; set; }
+ }
+
+ ///
+ /// The type of words to be listed from the custom language model's words resource: all (the default) shows all words. user shows only custom words that were added or modified by the user. corpora shows only OOV that were extracted from corpora.
+ ///
+ public class WordType
+ {
+ ///
+ /// All words.
+ ///
+ public const string ALL = "all";
+ ///
+ /// User words.
+ ///
+ public const string USER = "user";
+ ///
+ /// Corpora words.
+ ///
+ public const string CORPORA = "corpora";
+ }
+
+ ///
+ /// Words object for adding words to a customization.
+ ///
+ [fsObject]
+ public class Words
+ {
+ ///
+ /// The words to add to a customization.
+ ///
+ public Word[] words { get; set; }
+ }
+
+ ///
+ /// A word to add to a customization.
+ ///
+ [fsObject]
+ public class Word
+ {
+ ///
+ /// The word.
+ ///
+ public string word { get; set; }
+ ///
+ /// What the word sounds like.
+ ///
+ public string[] sounds_like { get; set; }
+ ///
+ /// How the word is displayed.
+ ///
+ public string display_as { get; set; }
+ }
+ #endregion
}
diff --git a/Scripts/Services/SpeechToText/SpeechToText.cs b/Scripts/Services/SpeechToText/SpeechToText.cs
old mode 100644
new mode 100755
index f5688eeb1..26100e048
--- a/Scripts/Services/SpeechToText/SpeechToText.cs
+++ b/Scripts/Services/SpeechToText/SpeechToText.cs
@@ -27,6 +27,8 @@
using System.Collections.Generic;
using UnityEngine;
using System.Text;
+using FullSerializer;
+using System.IO;
namespace IBM.Watson.DeveloperCloud.Services.SpeechToText.v1
{
@@ -62,46 +64,47 @@ public class SpeechToText : IWatsonService
#region Public Types
///
- /// This callback object is used by the Recognize() and StartListening() methods.
- ///
- /// The ResultList object containing the results.
- public delegate void OnRecognize(SpeechResultList results);
- ///
- /// This callback object is used by the GetModels() method.
- ///
- ///
- public delegate void OnGetModels(SpeechModel[] models);
- ///
/// This callback is used to return errors through the OnError property.
///
/// A string containing the error message.
public delegate void ErrorEvent(string error);
- #endregion
-
- #region Private Data
- private OnRecognize m_ListenCallback = null; // Callback is set by StartListening()
- private WSConnector m_ListenSocket = null; // WebSocket object used when StartListening() is invoked
+ ///
+ /// The delegate for loading a file.
+ ///
+ /// The filename to load.
+ /// Should return a byte array of the file contents or null of failure.
+ public delegate byte[] LoadFileDelegate(string filename);
+ ///
+ /// Set this property to overload the internal file loading of this class.
+ ///
+ public LoadFileDelegate LoadFile { get; set; }
+ #endregion
+
+ #region Private Data
+ private OnRecognize m_ListenCallback = null; // Callback is set by StartListening()
+ private WSConnector m_ListenSocket = null; // WebSocket object used when StartListening() is invoked
private bool m_ListenActive = false;
private bool m_AudioSent = false;
private bool m_IsListening = false;
private Queue m_ListenRecordings = new Queue();
- private int m_KeepAliveRoutine = 0; // ID of the keep alive co-routine
+ private int m_KeepAliveRoutine = 0; // ID of the keep alive co-routine
private DateTime m_LastKeepAlive = DateTime.Now;
private DateTime m_LastStartSent = DateTime.Now;
- private string m_RecognizeModel = "en-US_BroadbandModel"; // ID of the model to use.
- private int m_MaxAlternatives = 1; // maximum number of alternatives to return.
+ private string m_RecognizeModel = "en-US_BroadbandModel"; // ID of the model to use.
+ private int m_MaxAlternatives = 1; // maximum number of alternatives to return.
private bool m_Timestamps = false;
private bool m_WordConfidence = false;
- private bool m_DetectSilence = true; // If true, then we will try not to record silence.
- private float m_SilenceThreshold = 0.03f; // If the audio level is below this value, then it's considered silent.
+ private bool m_DetectSilence = true; // If true, then we will try not to record silence.
+ private float m_SilenceThreshold = 0.03f; // If the audio level is below this value, then it's considered silent.
private int m_RecordingHZ = -1;
- #endregion
-
- #region Public Properties
- ///
- /// True if StartListening() has been called.
- ///
- public bool IsListening { get { return m_IsListening; } private set { m_IsListening = value; } }
+ private static fsSerializer sm_Serializer = new fsSerializer();
+ #endregion
+
+ #region Public Properties
+ ///
+ /// True if StartListening() has been called.
+ ///
+ public bool IsListening { get { return m_IsListening; } private set { m_IsListening = value; } }
///
/// True if AudioData has been sent and we are recognizing speech.
///
@@ -158,7 +161,180 @@ public string RecognizeModel
public float SilenceThreshold { get { return m_SilenceThreshold; } set { m_SilenceThreshold = value; } }
#endregion
- #region Listening Functions
+ #region Get Models
+ ///
+ /// This callback object is used by the GetModels() method.
+ ///
+ ///
+ public delegate void OnGetModels(Model[] models);
+
+ ///
+ /// This function retrieves all the language models that the user may use by setting the RecognizeModel
+ /// public property.
+ ///
+ /// This callback is invoked with an array of all available models. The callback will
+ /// be invoked with null on error.
+ /// Returns true if request has been made.
+ public bool GetModels(OnGetModels callback)
+ {
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/models");
+ if (connector == null)
+ return false;
+
+ GetModelsRequest req = new GetModelsRequest();
+ req.Callback = callback;
+ req.OnResponse = OnGetModelsResponse;
+
+ return connector.Send(req);
+ }
+
+ private class GetModelsRequest : RESTConnector.Request
+ {
+ public OnGetModels Callback { get; set; }
+ };
+
+ private void OnGetModelsResponse(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ GetModelsRequest gmr = req as GetModelsRequest;
+ if (gmr == null)
+ throw new WatsonException("Unexpected request type.");
+
+ Model[] models = null;
+ if (resp.Success)
+ {
+ models = ParseGetModelsResponse(resp.Data);
+ if (models == null)
+ Log.Error("SpeechToText", "Failed to parse GetModels response.");
+ }
+ if (gmr.Callback != null)
+ gmr.Callback(models);
+ }
+
+ private Model[] ParseGetModelsResponse(byte[] data)
+ {
+ string jsonString = Encoding.UTF8.GetString(data);
+ if (jsonString == null)
+ {
+ Log.Error("SpeechToText", "Failed to get JSON string from response.");
+ return null;
+ }
+
+ IDictionary json = (IDictionary)Json.Deserialize(jsonString);
+ if (json == null)
+ {
+ Log.Error("SpechToText", "Failed to parse JSON: {0}", jsonString);
+ return null;
+ }
+
+ try
+ {
+ List models = new List();
+
+ IList imodels = json["models"] as IList;
+ if (imodels == null)
+ throw new Exception("Expected IList");
+
+ foreach (var m in imodels)
+ {
+ IDictionary imodel = m as IDictionary;
+ if (imodel == null)
+ throw new Exception("Expected IDictionary");
+
+ Model model = new Model();
+ model.name = (string)imodel["name"];
+ model.rate = (long)imodel["rate"];
+ model.language = (string)imodel["language"];
+ model.description = (string)imodel["description"];
+ model.url = (string)imodel["url"];
+
+ models.Add(model);
+ }
+
+ return models.ToArray();
+ }
+ catch (Exception e)
+ {
+ Log.Error("SpeechToText", "Caught exception {0} when parsing GetModels() response: {1}", e.ToString(), jsonString);
+ }
+
+ return null;
+ }
+ #endregion
+
+ #region Get Model
+ ///
+ /// This callback object is used by the GetModel() method.
+ ///
+ /// The resultant model.
+ public delegate void OnGetModel(Model model);
+
+ ///
+ /// This function retrieves a specified languageModel.
+ ///
+ /// This callback is invoked with the requested model. The callback will
+ /// be invoked with null on error.
+ /// The name of the model to get.
+ /// Returns true if request has been made.
+ public bool GetModel(OnGetModel callback, string modelID)
+ {
+ if (string.IsNullOrEmpty(modelID))
+ throw new ArgumentNullException("modelID");
+
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/models/" + modelID);
+ if (connector == null)
+ return false;
+
+ GetModelRequest req = new GetModelRequest();
+ req.Callback = callback;
+ req.ModelID = modelID;
+ req.OnResponse = OnGetModelResponse;
+
+ return connector.Send(req);
+ }
+
+ private class GetModelRequest : RESTConnector.Request
+ {
+ public OnGetModel Callback { get; set; }
+ public string ModelID { get; set; }
+ };
+
+ private void OnGetModelResponse(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ Model response = new Model();
+ if (resp.Success)
+ {
+ try
+ {
+ fsData data = null;
+ fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+
+ object obj = response;
+ r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+ }
+ catch(Exception e)
+ {
+ Log.Error("SpeechToText", "Caught exception {0} when parsing GetModel() response: {1}", e.ToString(), Encoding.UTF8.GetString(resp.Data));
+ }
+
+ if (resp == null)
+ Log.Error("SpeechToText", "Failed to parse GetModel response.");
+ }
+
+ if (((GetModelRequest)req).Callback != null)
+ ((GetModelRequest)req).Callback(resp.Success ? response :null);
+ }
+ #endregion
+
+ #region Sessionless - Streaming
+ ///
+ /// This callback object is used by the Recognize() and StartListening() methods.
+ ///
+ /// The ResultList object containing the results.
+ public delegate void OnRecognize(SpeechRecognitionEvent results);
///
/// This starts the service listening and it will invoke the callback for any recognized speech.
@@ -359,7 +535,7 @@ private void OnListenMessage(WSConnector.Message msg)
{
if (json.Contains("results"))
{
- SpeechResultList results = ParseRecognizeResponse(json);
+ SpeechRecognitionEvent results = ParseRecognizeResponse(json);
if (results != null)
{
// when we get results, start listening for the next block ..
@@ -438,104 +614,9 @@ private void OnListenClosed(WSConnector connector)
OnError("Disconnected from server.");
}
}
-
- #endregion
-
- #region GetModels Functions
- ///
- /// This function retrieves all the language models that the user may use by setting the RecognizeModel
- /// public property.
- ///
- /// This callback is invoked with an array of all available models. The callback will
- /// be invoked with null on error.
- /// Returns true if request has been made.
- public bool GetModels(OnGetModels callback)
- {
- RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/models");
- if (connector == null)
- return false;
-
- GetModelsRequest req = new GetModelsRequest();
- req.Callback = callback;
- req.OnResponse = OnGetModelsResponse;
-
- return connector.Send(req);
- }
-
- private class GetModelsRequest : RESTConnector.Request
- {
- public OnGetModels Callback { get; set; }
- };
-
- private void OnGetModelsResponse(RESTConnector.Request req, RESTConnector.Response resp)
- {
- GetModelsRequest gmr = req as GetModelsRequest;
- if (gmr == null)
- throw new WatsonException("Unexpected request type.");
-
- SpeechModel[] models = null;
- if (resp.Success)
- {
- models = ParseGetModelsResponse(resp.Data);
- if (models == null)
- Log.Error("SpeechToText", "Failed to parse GetModels response.");
- }
- if (gmr.Callback != null)
- gmr.Callback(models);
- }
-
- private SpeechModel[] ParseGetModelsResponse(byte[] data)
- {
- string jsonString = Encoding.UTF8.GetString(data);
- if (jsonString == null)
- {
- Log.Error("SpeechToText", "Failed to get JSON string from response.");
- return null;
- }
-
- IDictionary json = (IDictionary)Json.Deserialize(jsonString);
- if (json == null)
- {
- Log.Error("SpechToText", "Failed to parse JSON: {0}", jsonString);
- return null;
- }
-
- try
- {
- List models = new List();
-
- IList imodels = json["models"] as IList;
- if (imodels == null)
- throw new Exception("Expected IList");
-
- foreach (var m in imodels)
- {
- IDictionary imodel = m as IDictionary;
- if (imodel == null)
- throw new Exception("Expected IDictionary");
-
- SpeechModel model = new SpeechModel();
- model.Name = (string)imodel["name"];
- model.Rate = (long)imodel["rate"];
- model.Language = (string)imodel["language"];
- model.Description = (string)imodel["description"];
- model.URL = (string)imodel["url"];
-
- models.Add(model);
- }
-
- return models.ToArray();
- }
- catch (Exception e)
- {
- Log.Error("SpeechToText", "Caught exception {0} when parsing GetModels() response: {1}", e.ToString(), jsonString);
- }
-
- return null;
- }
#endregion
- #region Recognize Functions
+ #region Sessionless Non-Streaming
///
/// This function POSTs the given audio clip the recognize function and convert speech into text. This function should be used
/// only on AudioClips under 4MB once they have been converted into WAV format. Use the StartListening() for continuous
@@ -588,7 +669,7 @@ private void OnRecognizeResponse(RESTConnector.Request req, RESTConnector.Respon
if (recognizeReq == null)
throw new WatsonException("Unexpected request type.");
- SpeechResultList result = null;
+ SpeechRecognitionEvent result = null;
if (resp.Success)
{
result = ParseRecognizeResponse(resp.Data);
@@ -600,7 +681,7 @@ private void OnRecognizeResponse(RESTConnector.Request req, RESTConnector.Respon
else
{
Log.Status("SpeechToText", "Received Recognize Response, Elapsed Time: {0}, Results: {1}",
- resp.ElapsedTime, result.Results.Length);
+ resp.ElapsedTime, result.results.Length);
}
}
else
@@ -612,7 +693,7 @@ private void OnRecognizeResponse(RESTConnector.Request req, RESTConnector.Respon
recognizeReq.Callback(result);
}
- private SpeechResultList ParseRecognizeResponse(byte[] json)
+ private SpeechRecognitionEvent ParseRecognizeResponse(byte[] json)
{
string jsonString = Encoding.UTF8.GetString(json);
if (jsonString == null)
@@ -625,14 +706,14 @@ private SpeechResultList ParseRecognizeResponse(byte[] json)
return ParseRecognizeResponse(resp);
}
- private SpeechResultList ParseRecognizeResponse(IDictionary resp)
+ private SpeechRecognitionEvent ParseRecognizeResponse(IDictionary resp)
{
if (resp == null)
return null;
try
{
- List results = new List();
+ List results = new List();
IList iresults = resp["results"] as IList;
if (iresults == null)
return null;
@@ -643,24 +724,24 @@ private SpeechResultList ParseRecognizeResponse(IDictionary resp)
if (iresults == null)
continue;
- SpeechResult result = new SpeechResult();
- result.Final = (bool)iresult["final"];
+ SpeechRecognitionResult result = new SpeechRecognitionResult();
+ result.final = (bool)iresult["final"];
IList ialternatives = iresult["alternatives"] as IList;
if (ialternatives == null)
continue;
- List alternatives = new List();
+ List alternatives = new List();
foreach (var a in ialternatives)
{
IDictionary ialternative = a as IDictionary;
if (ialternative == null)
continue;
- SpeechAlt alternative = new SpeechAlt();
- alternative.Transcript = (string)ialternative["transcript"];
+ SpeechRecognitionAlternative alternative = new SpeechRecognitionAlternative();
+ alternative.transcript = (string)ialternative["transcript"];
if (ialternative.Contains("confidence"))
- alternative.Confidence = (double)ialternative["confidence"];
+ alternative.confidence = (double)ialternative["confidence"];
if (ialternative.Contains("timestamps"))
{
@@ -704,11 +785,11 @@ private SpeechResultList ParseRecognizeResponse(IDictionary resp)
alternatives.Add(alternative);
}
- result.Alternatives = alternatives.ToArray();
+ result.alternatives = alternatives.ToArray();
results.Add(result);
}
- return new SpeechResultList(results.ToArray());
+ return new SpeechRecognitionEvent(results.ToArray());
}
catch (Exception e)
{
@@ -716,11 +797,1035 @@ private SpeechResultList ParseRecognizeResponse(IDictionary resp)
return null;
}
}
- #endregion
-
- #region IWatsonService interface
- ///
- public string GetServiceID()
+ #endregion
+
+ #region Asynchronous
+ #endregion
+
+ #region Get Custom Models
+ ///
+ /// This callback is used by the GetCustomizations() function.
+ ///
+ /// The customizations
+ /// Optional custom data.
+ public delegate void GetCustomizationsCallback(Customizations customizations, string data);
+
+ ///
+ /// Lists information about all custom language models that are owned by the calling user. Use the language query parameter to see all custom models for the specified language; omit the parameter to see all custom models for all languages.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The language for which custom models are to be returned. Currently, only en-US (the default) is supported.
+ /// Optional custom data.
+ ///
+ public bool GetCustomizations(GetCustomizationsCallback callback, string language = "en-US", string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+
+ GetCustomizationsReq req = new GetCustomizationsReq();
+ req.Callback = callback;
+ req.Data = customData;
+ req.Language = language;
+ req.Parameters["language"] = language;
+ req.OnResponse = OnGetCustomizationsResp;
+
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/customizations");
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class GetCustomizationsReq : RESTConnector.Request
+ {
+ public GetCustomizationsCallback Callback { get; set; }
+ public string Language { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnGetCustomizationsResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ Customizations customizations = new Customizations();
+ if (resp.Success)
+ {
+ try
+ {
+ fsData data = null;
+ fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+
+ object obj = customizations;
+ r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+ }
+ catch (Exception e)
+ {
+ Log.Error("Speech To Text", "GetCustomizations Exception: {0}", e.ToString());
+ resp.Success = false;
+ }
+ }
+
+ if (((GetCustomizationsReq)req).Callback != null)
+ ((GetCustomizationsReq)req).Callback(resp.Success ? customizations : null, ((GetCustomizationsReq)req).Data);
+ }
+ #endregion
+
+ #region Create Custom Model
+ ///
+ /// Thid callback is used by the CreateCustomization() function.
+ ///
+ /// The customizationID.
+ /// Optional custom data.
+ public delegate void CreateCustomizationCallback(CustomizationID customizationID, string data);
+
+ ///
+ /// Creates a new custom language model for a specified base language model. The custom language model can be used only with the base language model for which it is created. The new model is owned by the individual whose service credentials are used to create it.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The custom model name.
+ /// The base model name - only en-US_BroadbandModel is currently supported.
+ /// Descripotion of the custom model.
+ /// Optional custom data.
+ ///
+ public bool CreateCustomization(CreateCustomizationCallback callback, string name, string base_model_name = "en-US_BroadbandModel", string description = default(string), string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(name))
+ throw new ArgumentNullException("A name is required to create a custom language model.");
+
+ CustomLanguage customLanguage = new CustomLanguage();
+ customLanguage.name = name;
+ customLanguage.base_model_name = base_model_name;
+ customLanguage.description = string.IsNullOrEmpty(description) ? name : description;
+
+ fsData data;
+ sm_Serializer.TrySerialize(customLanguage.GetType(), customLanguage, out data).AssertSuccessWithoutWarnings();
+ string customizationJson = fsJsonPrinter.CompressedJson(data);
+
+ CreateCustomizationRequest req = new CreateCustomizationRequest();
+ req.Callback = callback;
+ req.CustomLanguage = customLanguage;
+ req.Data = customData;
+ req.Headers["Content-Type"] = "application/json";
+ req.Headers["Accept"] = "application/json";
+ req.Send = Encoding.UTF8.GetBytes(customizationJson);
+ req.OnResponse = OnCreateCustomizationResp;
+
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/customizations");
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class CreateCustomizationRequest : RESTConnector.Request
+ {
+ public CreateCustomizationCallback Callback { get; set; }
+ public CustomLanguage CustomLanguage { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnCreateCustomizationResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ CustomizationID customizationID = new CustomizationID();
+ if (resp.Success)
+ {
+ try
+ {
+ fsData data = null;
+ fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+
+ object obj = customizationID;
+ r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+ }
+ catch (Exception e)
+ {
+ Log.Error("Speech To Text", "CreateCustomization Exception: {0}", e.ToString());
+ resp.Success = false;
+ }
+ }
+
+ if (((CreateCustomizationRequest)req).Callback != null)
+ ((CreateCustomizationRequest)req).Callback(resp.Success ? customizationID : null, ((CreateCustomizationRequest)req).Data);
+ }
+ #endregion
+
+ #region Delete Custom Model
+ ///
+ /// This callback is used by the DeleteCustomization() function.
+ ///
+ ///
+ ///
+ public delegate void OnDeleteCustomizationCallback(bool success, string data);
+ ///
+ /// Deletes an existing custom language model. Only the owner of a custom model can use this method to delete the model.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The customization ID to be deleted.
+ /// Optional customization data.
+ ///
+ public bool DeleteCustomization(OnDeleteCustomizationCallback callback, string customizationID, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to delete is required for DeleteCustomization");
+
+ DeleteCustomizationRequest req = new DeleteCustomizationRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.Data = customData;
+ req.Delete = true;
+ req.OnResponse = OnDeleteCustomizationResp;
+
+ string service = "/v1/customizations/{0}";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class DeleteCustomizationRequest : RESTConnector.Request
+ {
+ public OnDeleteCustomizationCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnDeleteCustomizationResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((DeleteCustomizationRequest)req).Callback != null)
+ ((DeleteCustomizationRequest)req).Callback(resp.Success, ((DeleteCustomizationRequest)req).Data);
+ }
+ #endregion
+
+ #region Get Custom Model
+ ///
+ /// This callback is used by the GetCusomization() function.
+ ///
+ ///
+ ///
+ public delegate void GetCustomizationCallback(Customization customization, string data);
+ ///
+ /// Lists information about a custom language model. Only the owner of a custom model can use this method to query information about the model.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The requested custom language model's identifier.
+ /// Optional custom data.
+ ///
+ public bool GetCustomization(GetCustomizationCallback callback, string customizationID, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to get a custom language model.");
+
+ GetCustomizationRequest req = new GetCustomizationRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.Data = customData;
+ req.OnResponse = OnGetCustomizationResp;
+
+ string service = "/v1/customizations/{0}";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class GetCustomizationRequest : RESTConnector.Request
+ {
+ public GetCustomizationCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnGetCustomizationResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ Customization customization = new Customization();
+ if (resp.Success)
+ {
+ try
+ {
+ fsData data = null;
+ fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+
+ object obj = customization;
+ r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+ }
+ catch (Exception e)
+ {
+ Log.Error("Speech To Text", "GetCustomization Exception: {0}", e.ToString());
+ resp.Success = false;
+ }
+ }
+
+ if (((GetCustomizationRequest)req).Callback != null)
+ ((GetCustomizationRequest)req).Callback(resp.Success ? customization : null, ((GetCustomizationRequest)req).Data);
+ }
+ #endregion
+
+ #region Train Custom Model
+ ///
+ /// This callback is used by the TrainCustomization() function.
+ ///
+ /// The success of the call.
+ /// Optional custom data.
+ public delegate void TrainCustomizationCallback(bool success, string data);
+ ///
+ /// Initiates the training of a custom language model with new corpora, words, or both.After adding training data to the custom model with the corpora or words methods, use this method to begin the actual training of the model on the new data.You can specify whether the custom model is to be trained with all words from its words resources or only with words that were added or modified by the user.Only the owner of a custom model can use this method to train the model.
+ /// This method is asynchronous and can take on the order of minutes to complete depending on the amount of data on which the service is being trained and the current load on the service.The method returns an HTTP 200 response code to indicate that the training process has begun.
+ /// You can monitor the status of the training by using the GET /v1/customizations/{customization_id} method to poll the model's status. Use a loop to check the status every 10 seconds. The method returns a Customization object that includes status and progress fields. A status of available means that the custom model is trained and ready to use. If training is in progress, the progress field indicates the progress of the training as a percentage complete.
+ /// Note: For this beta release, the progress field does not reflect the current progress of the training. The field changes from 0 to 100 when training is complete.
+ /// Training can fail to start for the following reasons:
+ /// No training data (corpora or words) have been added to the custom model.
+ /// Pre-processing of corpora to generate a list of out-of-vocabulary (OOV) words is not complete.
+ /// Pre-processing of words to validate or auto-generate sounds-like pronunciations is not complete.
+ /// One or more words that were added to the custom model have invalid sounds-like pronunciations that you must fix.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The requested custom language model's identifier.
+ /// Optional custom data.
+ ///
+ public bool TrainCustomization(TrainCustomizationCallback callback, string customizationID, string wordTypeToAdd = WordTypeToAdd.ALL, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to train a custom language model.");
+
+ TrainCustomizationRequest req = new TrainCustomizationRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.Data = customData;
+ req.Parameters["word_type_to_add"] = wordTypeToAdd;
+ req.Headers["Content-Type"] = "application/json";
+ req.Headers["Accept"] = "application/json";
+ req.Send = Encoding.UTF8.GetBytes("{}");
+ req.OnResponse = OnTrainCustomizationResp;
+
+ string service = "/v1/customizations/{0}/train";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class TrainCustomizationRequest : RESTConnector.Request
+ {
+ public TrainCustomizationCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnTrainCustomizationResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((TrainCustomizationRequest)req).Callback != null)
+ ((TrainCustomizationRequest)req).Callback(resp.Success, ((TrainCustomizationRequest)req).Data);
+ }
+ #endregion
+
+ #region Reset Custom Model
+ ///
+ /// This callback is used by the ResetCustomization() function.
+ ///
+ /// The success of the call.
+ /// Optional custom data.
+ public delegate void ResetCustomizationCallback(bool success, string data);
+ ///
+ /// Resets a custom language model by removing all corpora and words from the model.Resetting a custom model initializes the model to its state when it was first created. Metadata such as the name and language of the model are preserved.Only the owner of a custom model can use this method to reset the model.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The requested custom language model's identifier.
+ /// Optional custom data.
+ ///
+ public bool ResetCustomization(ResetCustomizationCallback callback, string customizationID, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to train a reset language model.");
+
+ ResetCustomizationRequest req = new ResetCustomizationRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.Data = customData;
+ req.Headers["Content-Type"] = "application/json";
+ req.Headers["Accept"] = "application/json";
+ req.Send = Encoding.UTF8.GetBytes("{}");
+ req.OnResponse = OnResetCustomizationResp;
+
+ string service = "/v1/customizations/{0}/reset";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class ResetCustomizationRequest : RESTConnector.Request
+ {
+ public ResetCustomizationCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnResetCustomizationResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((ResetCustomizationRequest)req).Callback != null)
+ ((ResetCustomizationRequest)req).Callback(resp.Success, ((ResetCustomizationRequest)req).Data);
+ }
+ #endregion
+
+ #region Upgrade Custom Model
+ ///
+ /// This callback is used by the UpgradeCustomization() function.
+ ///
+ /// The success of the call.
+ /// Optional custom data.
+ public delegate void UpgradeCustomizationCallback(bool success, string data);
+ ///
+ /// Upgrades a custom language model to the latest release level of the Speech to Text service. The method bases the upgrade on the latest trained data stored for the custom model. If the corpora or words for the model have changed since the model was last trained, you must use the POST /v1/customizations/{customization_id}/train method to train the model on the new data. Only the owner of a custom model can use this method to upgrade the model.
+ /// Note: This method is not currently implemented.It will be added for a future release of the API.
+ ///
+ /// The callback.
+ /// The requested custom language model's identifier.
+ /// Optional custom data.
+ ///
+ public bool UpgradeCustomization(UpgradeCustomizationCallback callback, string customizationID, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to upgrade a custom language model.");
+
+ UpgradeCustomizationRequest req = new UpgradeCustomizationRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.Data = customData;
+ req.Headers["Content-Type"] = "application/json";
+ req.Headers["Accept"] = "application/json";
+ req.Send = Encoding.UTF8.GetBytes("{}");
+ req.OnResponse = OnResetCustomizationResp;
+
+ string service = "/v1/customizations/{0}/upgrade";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class UpgradeCustomizationRequest : RESTConnector.Request
+ {
+ public UpgradeCustomizationCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnUpgradeCustomizationResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((UpgradeCustomizationRequest)req).Callback != null)
+ ((UpgradeCustomizationRequest)req).Callback(resp.Success, ((UpgradeCustomizationRequest)req).Data);
+ }
+ #endregion
+
+ #region Get Custom Corpora
+ ///
+ /// This callback is used by the GetCustomCorpora() function.
+ ///
+ /// The corpora
+ /// Optional custom data.
+ public delegate void GetCustomCorporaCallback(Corpora corpora, string data);
+
+ ///
+ /// Lists information about all corpora that have been added to the specified custom language model. The information includes the total number of words and out-of-vocabulary (OOV) words, name, and status of each corpus. Only the owner of a custom model can use this method to list the model's corpora.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The language for which custom models are to be returned. Currently, only en-US (the default) is supported.
+ /// Optional custom data.
+ ///
+ public bool GetCustomCorpora(GetCustomCorporaCallback callback, string customizationID, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID is required to GetCustomCorpora");
+
+ GetCustomCorporaReq req = new GetCustomCorporaReq();
+ req.Callback = callback;
+ req.Data = customData;
+ req.CustomizationID = customizationID;
+ req.OnResponse = OnGetCustomCorporaResp;
+
+ string service = "/v1/customizations/{0}/corpora";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class GetCustomCorporaReq : RESTConnector.Request
+ {
+ public GetCustomCorporaCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnGetCustomCorporaResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ Corpora corpora = new Corpora();
+ if (resp.Success)
+ {
+ try
+ {
+ fsData data = null;
+ fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+
+ object obj = corpora;
+ r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+ }
+ catch (Exception e)
+ {
+ Log.Error("Speech To Text", "OnGetCustomCorporaResp Exception: {0}", e.ToString());
+ resp.Success = false;
+ }
+ }
+
+ if (((GetCustomCorporaReq)req).Callback != null)
+ ((GetCustomCorporaReq)req).Callback(resp.Success ? corpora : null, ((GetCustomCorporaReq)req).Data);
+ }
+ #endregion
+
+ #region Delete Custom Corpus
+ ///
+ /// This callback is used by the DeleteCustomCorpus() function.
+ ///
+ ///
+ ///
+ public delegate void OnDeleteCustomCorpusCallback(bool success, string data);
+ ///
+ /// Deletes an existing corpus from a custom language model. The service removes any out-of-vocabulary (OOV) words associated with the corpus from the custom model's words resource unless they were also added by another corpus or they have been modified in some way with the POST /v1/customizations/{customization_id}/words or PUT /v1/customizations/{customization_id}/words/{word_name} method. Removing a corpus does not affect the custom model until you train the model with the POST /v1/customizations/{customization_id}/train method. Only the owner of a custom model can use this method to delete a corpus from the model.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The customization ID with the corpus to be deleted.
+ /// The corpus name to be deleted.
+ /// Optional customization data.
+ ///
+ public bool DeleteCustomCorpus(OnDeleteCustomCorpusCallback callback, string customizationID, string corpusName, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID is required for DeleteCustomCorpora.");
+ if (string.IsNullOrEmpty(corpusName))
+ throw new ArgumentNullException("A corpusName to delete is required to DeleteCustomCorpora.");
+
+ DeleteCustomCorpusRequest req = new DeleteCustomCorpusRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.CorpusName = corpusName;
+ req.Data = customData;
+ req.Delete = true;
+ req.OnResponse = OnDeleteCustomCorpusResp;
+
+ string service = "/v1/customizations/{0}/corpora/{1}";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID, corpusName));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class DeleteCustomCorpusRequest : RESTConnector.Request
+ {
+ public OnDeleteCustomCorpusCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string CorpusName { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnDeleteCustomCorpusResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((DeleteCustomCorpusRequest)req).Callback != null)
+ ((DeleteCustomCorpusRequest)req).Callback(resp.Success, ((DeleteCustomCorpusRequest)req).Data);
+ }
+ #endregion
+
+ #region Add Custom Coprpus
+ ///
+ /// This callback is used by the AddCustomCorpus() function.
+ ///
+ ///
+ ///
+ public delegate void OnAddCustomCorpusCallback(bool success, string data);
+ ///
+ /// Adds a single corpus text file of new training data to the custom language model. Use multiple requests to submit multiple corpus text files. Only the owner of a custom model can use this method to add a corpus to the model.
+ /// Submit a plain text file that contains sample sentences from the domain of interest to enable the service to extract words in context.The more sentences you add that represent the context in which speakers use words from the domain, the better the service's recognition accuracy. Adding a corpus does not affect the custom model until you train the model for the new data by using the POST /v1/customizations/{customization_id}/train method.
+ /// Use the following guidelines to prepare a corpus text file:
+ /// - Provide a plain text file that is encoded in UTF-8 if it contains non-ASCII characters.The service assumes UTF-8 encoding if it encounters such characters.
+ /// - Include each sentence of the corpus on its own line, terminating each line with a carriage return. Including multiple sentences on the same line can degrade accuracy.
+ /// - Use consistent capitalization for words in the corpus. The words resource is case-sensitive; mix upper- and lowercase letters and use capitalization only when intended.
+ /// - Beware of typographical errors.The service assumes that typos are new words; unless you correct them before training the model, the service adds them to the model's vocabulary.
+ /// The service automatically does the following:
+ /// - Converts numbers to their equivalent words.For example:
+ /// 500 becomes five hundred
+ /// and
+ /// 0.15 becomes zero point fifteen
+ /// - Removes the following punctuation and special characters:
+ /// ! @ # $ % ^ & * - + = ~ _ . , ; : ( ) < > [ ] { }
+ /// - Ignores phrases enclosed in ( ) (parentheses), < > (angle brackets), [] (square brackets), and { } (curly braces).
+ /// - Converts tokens that include certain symbols to meaningful strings.For example, the service converts a $ (dollar sign) followed by a number to its string representation:
+ /// $100 becomes one hundred dollars
+ /// and it converts a % (percent sign) preceded by a number to its string representation:
+ /// 100% becomes one hundred percent
+ /// This list is not exhaustive; the service makes similar adjustments for other characters as needed.
+ ///
+ /// The call returns an HTTP 201 response code if the corpus is valid.It then asynchronously pre-processes the contents of the corpus and automatically extracts new words that it finds.This can take on the order of a minute or two to complete depending on the total number of words and the number of new words in the corpus, as well as the current load on the service.You cannot submit requests to add additional corpora or words to the custom model, or to train the model, until the service's analysis of the corpus for the current request completes. Use the GET /v1/customizations/{customization_id}/corpora method to check the status of the analysis.
+ ///
+ /// The service auto-populates the model's words resource with any word that is not found in its base vocabulary; these are referred to as out-of-vocabulary (OOV) words. You can use the GET /v1/customizations/{customization_id}/words method to examine the words resource, using other words method to eliminate typos and modify how words are pronounced as needed.
+ ///
+ /// To add a corpus file that has the same name as an existing corpus, set the allow_overwrite query parameter to true; otherwise, the request fails.Overwriting an existing corpus causes the service to process the corpus text file and extract OOV words anew.Before doing so, it removes any OOV words associated with the existing corpus from the model's words resource unless they were also added by another corpus or they have been modified in some way with the POST /v1/customizations/{customization_id}/words or PUT /v1/customizations/{customization_id}/words/{word_name} method.
+ ///
+ /// The service limits the overall amount of data that you can add to a custom model to a maximum of 10 million total words from all corpora combined.Also, you can add no more than 30 thousand new words to a model; this includes words that the service extracts from corpora and words that you add directly.
+ /// Note: This method is currently a beta release that is available for US English only
+ ///
+ /// The callback.
+ /// The customization ID with the corpus to be deleted.
+ /// The corpus name to be deleted.
+ /// Allow overwriting of corpus data.
+ /// A file path to plain text training data.
+ /// Optional customization data.
+ ///
+ public bool AddCustomCorpus(OnAddCustomCorpusCallback callback, string customizationID, string corpusName, bool allowOverwrite, string trainingPath, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID is required for AddCustomCorpus.");
+ if (string.IsNullOrEmpty(corpusName))
+ throw new ArgumentNullException("A corpusName is required to AddCustomCorpus.");
+ if (string.IsNullOrEmpty(trainingPath))
+ throw new ArgumentNullException("A path to training data is required to AddCustomCorpus");
+
+ byte[] trainingDataBytes = null;
+
+ if (!string.IsNullOrEmpty(trainingPath))
+ {
+ if (LoadFile != null)
+ {
+ trainingDataBytes = LoadFile(trainingPath);
+ }
+ else
+ {
+#if !UNITY_WEBPLAYER
+ trainingDataBytes = File.ReadAllBytes(trainingPath);
+#endif
+ }
+
+ if (trainingDataBytes == null)
+ Log.Error("SpeechToText", "Failed to upload {0}!", trainingPath);
+ }
+
+ return AddCustomCorpus(callback, customizationID, corpusName, allowOverwrite, trainingDataBytes);
+ }
+
+ ///
+ /// Overload method for AddCustomCorpus that takes byteArray training data.
+ ///
+ /// The callback.
+ /// The customization ID with the corpus to be deleted.
+ /// The corpus name to be deleted.
+ /// Allow overwriting of corpus data.
+ /// ByteArray data for training data.
+ /// Optional customization data.
+ public bool AddCustomCorpus(OnAddCustomCorpusCallback callback, string customizationID, string corpusName, bool allowOverwrite, byte[] trainingData, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID is required for AddCustomCorpus.");
+ if (string.IsNullOrEmpty(corpusName))
+ throw new ArgumentNullException("A corpusName is requried for AddCustomCorpus.");
+ if (trainingData == default(byte[]))
+ throw new ArgumentNullException("Training data is required for AddCustomCorpus.");
+
+ AddCustomCorpusRequest req = new AddCustomCorpusRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.CorpusName = corpusName;
+ req.Data = customData;
+ req.Headers["Content-Type"] = "application/x-www-form-urlencoded";
+ req.Headers["Accept"] = "application/json";
+ req.Parameters["allow_overwrite"] = allowOverwrite.ToString();
+ req.Forms = new Dictionary();
+ req.Forms["body"] = new RESTConnector.Form(trainingData, "trainingData.txt", "text/plain");
+ req.OnResponse = OnAddCustomCorpusResp;
+
+ string service = "/v1/customizations/{0}/corpora/{1}";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID, corpusName));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class AddCustomCorpusRequest : RESTConnector.Request
+ {
+ public OnAddCustomCorpusCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string CorpusName { get; set; }
+ public bool AllowOverwrite { get; set; }
+ public byte[] TrainingData { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnAddCustomCorpusResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((AddCustomCorpusRequest)req).Callback != null)
+ ((AddCustomCorpusRequest)req).Callback(resp.Success, ((AddCustomCorpusRequest)req).Data);
+ }
+ #endregion
+
+ #region Get Custom Words
+ ///
+ /// This callback is used by the GetCustomWords() function.
+ ///
+ /// The custom words
+ /// Optional custom data.
+ public delegate void GetCustomWordsCallback(WordsList wordList, string data);
+
+ ///
+ /// Lists information about all custom words from a custom language model. You can list all words from the custom model's words resource, only custom words that were added or modified by the user, or only OOV words that were extracted from corpora. Only the owner of a custom model can use this method to query the words from the model.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The language for which custom models are to be returned. Currently, only en-US (the default) is supported.
+ /// Optional custom data.
+ ///
+ public bool GetCustomWords(GetCustomWordsCallback callback, string customizationID, string wordType = WordType.ALL, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("customizationID");
+
+ GetCustomWordsReq req = new GetCustomWordsReq();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.WordType = wordType;
+ req.Data = customData;
+ req.Parameters["word_type"] = wordType.ToString();
+ req.OnResponse = OnGetCustomWordsResp;
+
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format("/v1/customizations/{0}/words", customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class GetCustomWordsReq : RESTConnector.Request
+ {
+ public GetCustomWordsCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string WordType { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnGetCustomWordsResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ WordsList wordsList = new WordsList();
+ if (resp.Success)
+ {
+ try
+ {
+ fsData data = null;
+ fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+
+ object obj = wordsList;
+ r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+ }
+ catch (Exception e)
+ {
+ Log.Error("Speech To Text", "OnGetCustomWordsResp Exception: {0}", e.ToString());
+ resp.Success = false;
+ }
+ }
+
+ if (((GetCustomWordsReq)req).Callback != null)
+ ((GetCustomWordsReq)req).Callback(resp.Success ? wordsList : null, ((GetCustomWordsReq)req).Data);
+ }
+ #endregion
+
+ #region Add Custom Words
+ ///
+ /// This callback is used by the AddCustomWords() function.
+ ///
+ /// The success of the call.
+ /// Optional custom data.
+ public delegate void AddCustomWordsCallback(bool success, string data);
+ ///
+ /// Adds one or more custom words to a custom language model.The service populates the words resource for a custom model with out-of-vocabulary(OOV) words found in each corpus added to the model.You can use this method to add additional words or to modify existing words in the words resource.Only the owner of a custom model can use this method to add or modify custom words associated with the model.Adding or modifying custom words does not affect the custom model until you train the model for the new data by using the POST /v1/customizations/{customization_id}/train method.
+ /// You add custom words by providing a Words object, which is an array of Word objects, one per word.You must use the object's word parameter to identify the word that is to be added. You can also provide one or both of the optional sounds_like and display_as fields for each word.
+ /// The sounds_like field provides an array of one or more pronunciations for the word. Use the parameter to specify how the word can be pronounced by users.Use the parameter for words that are difficult to pronounce, foreign words, acronyms, and so on.For example, you might specify that the word IEEE can sound like i triple e.You can specify a maximum of five sounds-like pronunciations for a word, and each pronunciation must adhere to the following rules:
+ /// Use English alphabetic characters: a-z and A-Z.
+ /// To pronounce a single letter, use the letter followed by a period, for example, N.C.A.A. for the word NCAA.
+ /// Use real or made-up words that are pronounceable in the native language, for example, shuchensnie for the word Sczcesny.
+ /// Substitute equivalent English letters for non-English letters, for example, s for ç or ny for ñ.
+ /// Substitute non-accented letters for accented letters, for example a for à or e for è.
+ /// Use the spelling of numbers, for example, seventy-five for 75.
+ /// You can include multiple words separated by spaces, but the service enforces a maximum of 40 total characters not including spaces.
+ /// The display_as field provides a different way of spelling the word in a transcript. Use the parameter when you want the word to appear different from its usual representation or from its spelling in corpora training data.For example, you might indicate that the word IBM(trademark) is to be displayed as IBM™.
+ /// If you add a custom word that already exists in the words resource for the custom model, the new definition overrides the existing data for the word.If the service encounters an error with the input data, it returns a failure code and does not add any of the words to the words resource.
+ /// The call returns an HTTP 201 response code if the input data is valid.It then asynchronously pre-processes the words to add them to the model's words resource. The time that it takes for the analysis to complete depends on the number of new words that you add but is generally faster than adding a corpus or training a model.
+ /// You can use the GET /v1/customizations/{ customization_id}/words or GET /v1/customizations/{customization_id}/words/{word_name} method to review the words that you add.Words with an invalid sounds_like field include an error field that describes the problem.You can use other words methods to correct errors, eliminate typos, and modify how words are pronounced as needed.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The requested custom language model's identifier.
+ /// A boolean used to differentiate overloads with identical input types..
+ /// A path to a json file to train.
+ /// Optional custom data.
+ ///
+ public bool AddCustomWords(AddCustomWordsCallback callback, string customizationID, bool useDataPath, string wordsJsonPath, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to add words to a custom language model.");
+ if (string.IsNullOrEmpty(wordsJsonPath))
+ throw new ArgumentNullException("A wordsJsonPath is required to add words to a custom language model.");
+
+ string wordsJson = File.ReadAllText(wordsJsonPath);
+
+ return AddCustomWords(callback, customizationID, wordsJson);
+ }
+
+ public bool AddCustomWords(AddCustomWordsCallback callback, string customizationID, Words words, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to add words to a custom language model.");
+ if (words == null || words.words == null || words.words.Length == 0)
+ throw new WatsonException("Custom words are required to add words to a custom language model.");
+
+ fsData data;
+ sm_Serializer.TrySerialize(words.GetType(), words, out data).AssertSuccessWithoutWarnings();
+ string wordsJson = fsJsonPrinter.CompressedJson(data);
+
+ return AddCustomWords(callback, customizationID, wordsJson, customData);
+ }
+
+ public bool AddCustomWords(AddCustomWordsCallback callback, string customizationID, string wordsJson, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID to add words to a custom language model.");
+ if (string.IsNullOrEmpty(wordsJson))
+ throw new ArgumentNullException("A wordsJsonPath is required to add words to a custom language model.");
+
+ AddCustomWordsRequest req = new AddCustomWordsRequest();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.WordsJson = wordsJson;
+ req.Data = customData;
+ req.Headers["Content-Type"] = "application/json";
+ req.Headers["Accept"] = "application/json";
+ req.Send = Encoding.UTF8.GetBytes(wordsJson);
+ req.OnResponse = OnAddCustomWordsResp;
+
+ string service = "/v1/customizations/{0}/words";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class AddCustomWordsRequest : RESTConnector.Request
+ {
+ public AddCustomWordsCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string WordsJson { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnAddCustomWordsResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((AddCustomWordsRequest)req).Callback != null)
+ ((AddCustomWordsRequest)req).Callback(resp.Success, ((AddCustomWordsRequest)req).Data);
+ }
+ #endregion
+
+ #region Delete Custom Word
+ ///
+ /// This callback is used by the DeleteCustomWord() function.
+ ///
+ ///
+ ///
+ public delegate void OnDeleteCustomWordCallback(bool success, string data);
+ ///
+ /// Deletes a custom word from a custom language model. You can remove any word that you added to the custom model's words resource via any means. However, if the word also exists in the service's base vocabulary, the service removes only the custom pronunciation for the word; the word remains in the base vocabulary.
+ /// Removing a custom word does not affect the custom model until you train the model with the POST /v1/customizations/{customization_id}/train method.Only the owner of a custom model can use this method to delete a word from the model.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The customization ID to be deleted.
+ /// Optional customization data.
+ ///
+ public bool DeleteCustomWord(OnDeleteCustomWordCallback callback, string customizationID, string word, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID is required for DeleteCustomWord");
+ if (string.IsNullOrEmpty(word))
+ throw new ArgumentNullException("A word to delete is requried for DeleteCustomWord");
+
+ DeleteCustomWordRequest req = new DeleteCustomWordRequest();req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.Word = word;
+ req.Data = customData;
+ req.Delete = true;
+ req.OnResponse = OnDeleteCustomWordResp;
+
+ string service = "/v1/customizations/{0}/words/{1}";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID, word));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class DeleteCustomWordRequest : RESTConnector.Request
+ {
+ public OnDeleteCustomWordCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Word { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnDeleteCustomWordResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ if (((DeleteCustomWordRequest)req).Callback != null)
+ ((DeleteCustomWordRequest)req).Callback(resp.Success, ((DeleteCustomWordRequest)req).Data);
+ }
+ #endregion
+
+ #region Get Custom Word
+ ///
+ /// This callback is used by the GetCustomWord() function.
+ ///
+ /// The word
+ /// Optional custom data.
+ public delegate void GetCustomWordCallback(WordData word, string data);
+
+ ///
+ /// Lists information about a custom word from a custom language model. Only the owner of a custom model can use this method to query a word from the model.
+ /// Note: This method is currently a beta release that is available for US English only.
+ ///
+ /// The callback.
+ /// The language for which custom models are to be returned. Currently, only en-US (the default) is supported.
+ /// Optional custom data.
+ ///
+ public bool GetCustomWord(GetCustomWordCallback callback, string customizationID, string word, string customData = default(string))
+ {
+ if (callback == null)
+ throw new ArgumentNullException("callback");
+ if (string.IsNullOrEmpty(customizationID))
+ throw new ArgumentNullException("A customizationID is required to GetCustomWord");
+ if (string.IsNullOrEmpty(word))
+ throw new ArgumentNullException("A word is required to GetCustomWord");
+
+ GetCustomWordReq req = new GetCustomWordReq();
+ req.Callback = callback;
+ req.CustomizationID = customizationID;
+ req.Word = word;
+ req.Data = customData;
+ req.OnResponse = OnGetCustomWordResp;
+
+ string service = "/v1/customizations/{0}/words/{1}";
+ RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID, word));
+ if (connector == null)
+ return false;
+
+ return connector.Send(req);
+ }
+
+ private class GetCustomWordReq : RESTConnector.Request
+ {
+ public GetCustomWordCallback Callback { get; set; }
+ public string CustomizationID { get; set; }
+ public string Word { get; set; }
+ public string Data { get; set; }
+ }
+
+ private void OnGetCustomWordResp(RESTConnector.Request req, RESTConnector.Response resp)
+ {
+ WordData word = new WordData();
+ if (resp.Success)
+ {
+ try
+ {
+ fsData data = null;
+ fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+
+ object obj = word;
+ r = sm_Serializer.TryDeserialize(data, obj.GetType(), ref obj);
+ if (!r.Succeeded)
+ throw new WatsonException(r.FormattedMessages);
+ }
+ catch (Exception e)
+ {
+ Log.Error("Speech To Text", "OnGetCustomWordResp Exception: {0}", e.ToString());
+ resp.Success = false;
+ }
+ }
+
+ if (((GetCustomWordReq)req).Callback != null)
+ ((GetCustomWordReq)req).Callback(resp.Success ? word : null, ((GetCustomWordReq)req).Data);
+ }
+ #endregion
+
+ #region IWatsonService interface
+ ///
+ public string GetServiceID()
{
return SERVICE_ID;
}
@@ -748,7 +1853,7 @@ public CheckServiceStatus(SpeechToText service, ServiceStatus callback)
m_Callback(SERVICE_ID, false);
}
- private void OnCheckService(SpeechModel[] models)
+ private void OnCheckService(Model[] models)
{
if (m_Callback != null && m_Callback.Target != null)
m_Callback(SERVICE_ID, models != null);
diff --git a/Scripts/Services/TextToSpeech/TextToSpeech.cs b/Scripts/Services/TextToSpeech/TextToSpeech.cs
index d86f6c392..72548baf2 100755
--- a/Scripts/Services/TextToSpeech/TextToSpeech.cs
+++ b/Scripts/Services/TextToSpeech/TextToSpeech.cs
@@ -702,7 +702,7 @@ private void OnGetCustomizationResp(RESTConnector.Request req, RESTConnector.Res
}
catch (Exception e)
{
- Log.Error("Text To Speech", "CreateCustomization Exception: {0}", e.ToString());
+ Log.Error("Text To Speech", "GetCustomization Exception: {0}", e.ToString());
resp.Success = false;
}
}
diff --git a/Scripts/UnitTests/TestSpeechToText.cs b/Scripts/UnitTests/TestSpeechToText.cs
old mode 100644
new mode 100755
index 01b922461..f4a314fc3
--- a/Scripts/UnitTests/TestSpeechToText.cs
+++ b/Scripts/UnitTests/TestSpeechToText.cs
@@ -20,34 +20,555 @@
using IBM.Watson.DeveloperCloud.Services.SpeechToText.v1;
using IBM.Watson.DeveloperCloud.Utilities;
using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
namespace IBM.Watson.DeveloperCloud.UnitTests
{
public class TestSpeechToText : UnitTest
{
private SpeechToText m_SpeechToText = new SpeechToText();
+
private bool m_GetModelsTested = false;
+ private bool m_GetModelTested = false;
+
+ private bool m_GetCustomizationsTested = false;
+ private bool m_CreateCustomizationTested = false;
+ private bool m_GetCustomizationTested = false;
+ private bool m_GetCustomCorporaTested = false;
+ private bool m_AddCustomCorpusTested = false;
+ private bool m_GetCustomWordsTested = false;
+ private bool m_AddCustomWordsUsingFileTested = false;
+ private bool m_AddCustomWordsUsingObjectTested = false;
+ private bool m_GetCustomWordTested = false;
+ private bool m_TrainCustomizationTested = false;
+ private bool m_DeleteCustomCorpusTested = false;
+ private bool m_DeleteCustomWordTested = false;
+ private bool m_ResetCustomizationTested = false;
+ private bool m_DeleteCustomizationTested = false;
+
+ private string m_CreatedCustomizationID;
+ private string m_CreatedCustomizationName = "unity-integration-test-customization";
+ private string m_CreatedCorpusName = "unity-integration-test-corpus";
+ private string m_CustomCorpusFilePath;
+ private string m_SpeechToTextModelEnglish = "en-US_BroadbandModel";
+ private string m_CustomWordsFilePath;
+ private bool m_AllowOverwrite = true;
+ private string m_WordToGet = "watson";
- public override IEnumerator RunTest()
+ private bool m_IsCustomizationBusy = false;
+
+ public override IEnumerator RunTest()
{
if (Config.Instance.FindCredentials(m_SpeechToText.GetServiceID()) == null)
yield break;
- m_SpeechToText.GetModels(OnGetModels);
+ m_CustomCorpusFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-corpus.txt";
+ m_CustomWordsFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/test-stt-words.json";
+ // GetModels
+ Log.Debug("TestSpeechToText", "********** Attempting to to GetModels");
+ m_SpeechToText.GetModels(HandleGetModels);
while (!m_GetModelsTested)
yield return null;
- yield break;
+ // GetModel
+ Log.Debug("TestSpeechToText", "********** Attempting to to GetModel {0}", m_SpeechToTextModelEnglish);
+ m_SpeechToText.GetModel(HandleGetModel, m_SpeechToTextModelEnglish);
+ while (!m_GetModelTested)
+ yield return null;
+
+ // GetCustomizations
+ Log.Debug("TestSpeechToText", "********** Attempting to to get customizations");
+ m_SpeechToText.GetCustomizations(HandleGetCustomizations);
+ while (!m_GetCustomizationsTested)
+ yield return null;
+
+ // CreateCustomization
+ Log.Debug("TestSpeechToText", "********** Attempting to to create customization {0}", m_CreatedCustomizationName);
+ m_SpeechToText.CreateCustomization(HandleCreateCustomization, m_CreatedCustomizationName);
+ while (!m_CreateCustomizationTested)
+ yield return null;
+
+ // GetCustomization
+ Log.Debug("TestSpeechToText", "********** Attempting to to get customization {0}", m_CreatedCustomizationID);
+ m_SpeechToText.GetCustomization(HandleGetCustomization, m_CreatedCustomizationID);
+ while (!m_GetCustomizationTested)
+ yield return null;
+
+ // GetCustomCorpora
+ Log.Debug("TestSpeechToText", "********** Attempting to to get custom corpora");
+ m_SpeechToText.GetCustomCorpora(HandleGetCustomCorpora, m_CreatedCustomizationID);
+ while (!m_GetCustomCorporaTested)
+ yield return null;
+
+ // AddCustomCorpus
+ Log.Debug("TestSpeechToText", "********** Attempting to to add custom corpus {0}", m_CreatedCorpusName);
+ m_SpeechToText.AddCustomCorpus(HandleAddCustomCorpus, m_CreatedCustomizationID, m_CreatedCorpusName, m_AllowOverwrite, m_CustomCorpusFilePath);
+ while (!m_AddCustomCorpusTested)
+ yield return null;
+
+ Runnable.Run(CheckCustomizationStatus(m_CreatedCustomizationID));
+ while (m_IsCustomizationBusy)
+ yield return null;
+
+ // GetCustomWords
+ Log.Debug("TestSpeechToText", "********** Attempting to to get custom words");
+ m_SpeechToText.GetCustomWords(HandleGetCustomWords, m_CreatedCustomizationID);
+ while (!m_GetCustomWordsTested)
+ yield return null;
+
+ // AddCustomWordsUsingFile
+ Log.Debug("TestSpeechToText", "********** Attempting to to add custom words using file {0}", m_CustomWordsFilePath);
+ m_SpeechToText.AddCustomWords(HandleAddCustomWordsUsingFile, m_CreatedCustomizationID, true, m_CustomWordsFilePath);
+ while (!m_AddCustomWordsUsingFileTested)
+ yield return null;
+
+ Runnable.Run(CheckCustomizationStatus(m_CreatedCustomizationID));
+ while (m_IsCustomizationBusy)
+ yield return null;
+
+ // AddCustomWordsUsingObject
+ Words words = new Words();
+ Word w0 = new Word();
+ List wordList = new List();
+ w0.word = "mikey";
+ w0.sounds_like = new string[1];
+ w0.sounds_like[0] = "my key";
+ w0.display_as = "Mikey";
+ wordList.Add(w0);
+ Word w1 = new Word();
+ w1.word = "charlie";
+ w1.sounds_like = new string[1];
+ w1.sounds_like[0] = "char lee";
+ w1.display_as = "Charlie";
+ wordList.Add(w1);
+ Word w2 = new Word();
+ w2.word = "bijou";
+ w2.sounds_like = new string[1];
+ w2.sounds_like[0] = "be joo";
+ w2.display_as = "Bijou";
+ wordList.Add(w2);
+ words.words = wordList.ToArray();
+
+ Log.Debug("TestSpeechToText", "********** Attempting to to add custom words using object");
+ m_SpeechToText.AddCustomWords(HandleAddCustomWordsUsingObject, m_CreatedCustomizationID, words);
+ while (!m_AddCustomWordsUsingObjectTested)
+ yield return null;
+
+ Runnable.Run(CheckCustomizationStatus(m_CreatedCustomizationID));
+ while (m_IsCustomizationBusy)
+ yield return null;
+
+ // GetCustomWord
+ Log.Debug("TestSpeechToText", "********** Attempting to to get custom word {0}", m_WordToGet);
+ m_SpeechToText.GetCustomWord(HandleGetCustomWord, m_CreatedCustomizationID, m_WordToGet);
+ while (!m_GetCustomWordTested)
+ yield return null;
+
+ // TrainCustomization
+ Log.Debug("TestSpeechToText", "********** Attempting to to train customization {0}", m_CreatedCustomizationID);
+ m_SpeechToText.TrainCustomization(HandleTrainCustomization, m_CreatedCustomizationID);
+ while (!m_TrainCustomizationTested)
+ yield return null;
+
+ Runnable.Run(CheckCustomizationStatus(m_CreatedCustomizationID));
+ while (m_IsCustomizationBusy)
+ yield return null;
+
+ // DeleteCustomCorpus
+ Log.Debug("TestSpeechToText", "********** Attempting to to delete custom corpus {0}", m_CreatedCorpusName);
+ m_SpeechToText.DeleteCustomCorpus(HandleDeleteCustomCorpus, m_CreatedCustomizationID, m_CreatedCorpusName);
+ while (!m_DeleteCustomCorpusTested)
+ yield return null;
+
+ Runnable.Run(CheckCustomizationStatus(m_CreatedCustomizationID));
+ while (m_IsCustomizationBusy)
+ yield return null;
+
+ // DeleteCustomWord
+ Log.Debug("TestSpeechToText", "********** Attempting to to delete custom word {0}", m_WordToGet);
+ m_SpeechToText.DeleteCustomWord(HandleDeleteCustomWord, m_CreatedCustomizationID, m_WordToGet);
+ while (!m_DeleteCustomWordTested)
+ yield return null;
+
+ Runnable.Run(CheckCustomizationStatus(m_CreatedCustomizationID));
+ while (m_IsCustomizationBusy)
+ yield return null;
+
+ // ResetCustomization
+ Log.Debug("TestSpeechToText", "********** Attempting to to reset customization {0}", m_CreatedCustomizationID);
+ m_SpeechToText.ResetCustomization(HandleResetCustomization, m_CreatedCustomizationID);
+ while (!m_ResetCustomizationTested)
+ yield return null;
+
+ // The customization is always pending after reset for some reason!
+ //Runnable.Run(CheckCustomizationStatus(m_CreatedCustomizationID));
+ //while (m_IsCustomizationBusy)
+ // yield return null;
+
+ // DeleteCustomization
+ Log.Debug("TestSpeechToText", "********** Attempting to to delete customization {0}", m_CreatedCustomizationID);
+ m_SpeechToText.DeleteCustomization(HandleDeleteCustomization, m_CreatedCustomizationID);
+ while (!m_DeleteCustomizationTested)
+ yield return null;
+
+ yield break;
}
- private void OnGetModels(SpeechModel[] models)
+ private void HandleGetModels(Model[] models)
{
- Test(models != null);
if (models != null)
Log.Status("TestSpeechToText", "GetModels() returned {0} models.", models.Length);
+ Test(models != null);
m_GetModelsTested = true;
}
- }
+
+ private void HandleGetModel(Model model)
+ {
+ if (model != null)
+ {
+ Log.Debug("TestSpeechToText", "Model - name: {0} | description: {1} | language:{2} | rate: {3} | sessions: {4} | url: {5} | customLanguageModel: {6}",
+ model.name, model.description, model.language, model.rate, model.sessions, model.url, model.supported_features.custom_language_model);
+ }
+ else
+ {
+ Log.Warning("TestSpeechToText", "Failed to get model!");
+ }
+
+ Test(model != null);
+ m_GetModelTested = true;
+ }
+
+ private void HandleGetCustomizations(Customizations customizations, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (customizations != null)
+ {
+ if (customizations.customizations.Length > 0)
+ {
+ foreach (Customization customization in customizations.customizations)
+ Log.Debug("TestSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status);
+
+ Log.Debug("TestSpeechToText", "GetCustomizations() succeeded!");
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "There are no customizations!");
+ }
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to get customizations!");
+ }
+
+ Test(customizations != null);
+ m_GetCustomizationsTested = true;
+ }
+
+ private void HandleCreateCustomization(CustomizationID customizationID, string customData)
+ {
+ if (customizationID != null)
+ {
+ Log.Debug("TestSpeechToText", "Customization created: {0}", customizationID.customization_id);
+ Log.Debug("TestSpeechToText", "CreateCustomization() succeeded!");
+
+ m_CreatedCustomizationID = customizationID.customization_id;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to create customization!");
+ }
+
+ Test(customizationID != null);
+ m_CreateCustomizationTested = true;
+ }
+
+ private void HandleDeleteCustomization(bool success, string customData)
+ {
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "Deleted customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("TestSpeechToText", "DeletedCustomization() succeeded!");
+ m_CreatedCustomizationID = default(string);
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to delete customization!");
+ }
+
+ Test(success);
+ m_DeleteCustomizationTested = true;
+ }
+
+ private void HandleGetCustomization(Customization customization, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (customization != null)
+ {
+ Log.Debug("TestSpeechToText", "Customization - name: {0} | description: {1} | status: {2}", customization.name, customization.description, customization.status);
+ Log.Debug("TestSpeechToText", "GetCustomization() succeeded!");
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to get customization {0}!", m_CreatedCustomizationID);
+ }
+
+ Test(customization != null);
+ m_GetCustomizationTested = true;
+ }
+
+ private void HandleTrainCustomization(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "Train customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("TestSpeechToText", "TrainCustomization() succeeded!");
+ m_IsCustomizationBusy = true;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to train customization!");
+ }
+
+ Test(success);
+ m_TrainCustomizationTested = true;
+ }
+
+ private void HandleUpgradeCustomization(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "Upgrade customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("TestSpeechToText", "UpgradeCustomization() succeeded!");
+
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to upgrade customization!");
+ }
+
+ Test(success);
+ //m_UpgradeCustomizationTested = true;
+ // Note: This method is not yet implemented!
+ }
+
+ private void HandleResetCustomization(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "Reset customization {0}!", m_CreatedCustomizationID);
+ Log.Debug("TestSpeechToText", "ResetCustomization() succeeded!");
+ //m_IsCustomizationBusy = true;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to reset customization!");
+ }
+
+ Test(success);
+ m_ResetCustomizationTested = true;
+ }
+
+ private void HandleGetCustomCorpora(Corpora corpora, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "CustomData: {0}", customData);
+
+ if (corpora != null)
+ {
+ if (corpora.corpora.Length > 0)
+ {
+ foreach (Corpus corpus in corpora.corpora)
+ Log.Debug("TestSpeechToText", "Corpus - name: {0} | total_words: {1} | out_of_vocabulary_words: {2} | staus: {3}",
+ corpus.name, corpus.total_words, corpus.out_of_vocabulary_words, corpus.status);
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "There are no custom corpora!");
+ }
+
+ Log.Debug("TestSpeechToText", "GetCustomCorpora() succeeded!");
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to get custom corpora!");
+ }
+
+ Test(corpora != null);
+ m_GetCustomCorporaTested = true;
+ }
+
+ private void HandleDeleteCustomCorpus(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "DeleteCustomCorpus() succeeded!");
+ m_IsCustomizationBusy = true;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to delete custom corpus!");
+ }
+
+ Test(success);
+ m_DeleteCustomCorpusTested = true;
+ }
+
+ private void HandleAddCustomCorpus(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "AddCustomCorpus() succeeded!");
+ m_IsCustomizationBusy = true;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to delete custom corpus!");
+ }
+
+ Test(success);
+ m_AddCustomCorpusTested = true;
+ }
+
+ private void HandleGetCustomWords(WordsList wordList, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (wordList != null)
+ {
+ if (wordList.words != null && wordList.words.Length > 0)
+ {
+ foreach (WordData word in wordList.words)
+ Log.Debug("TestSpeechToText", "WordData - word: {0} | sounds like[0]: {1} | display as: {2} | source[0]: {3}", word.word, word.sounds_like[0], word.display_as, word.source[0]);
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "No custom words found!");
+ }
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to get custom words!");
+ }
+
+ Test(wordList != null);
+ m_GetCustomWordsTested = true;
+ }
+
+ private void HandleAddCustomWordsUsingFile(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "AddCustomWords() using file succeeded!");
+ m_IsCustomizationBusy = true;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to add custom words using file!");
+ }
+
+ Test(success);
+ m_AddCustomWordsUsingFileTested = true;
+ }
+
+ private void HandleAddCustomWordsUsingObject(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "AddCustomWords() using object succeeded!");
+ m_IsCustomizationBusy = true;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to add custom words using object!");
+ }
+
+ Test(success);
+ m_AddCustomWordsUsingObjectTested = true;
+ }
+
+ private void HandleDeleteCustomWord(bool success, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (success)
+ {
+ Log.Debug("TestSpeechToText", "DeleteCustomWord() succeeded!");
+ m_IsCustomizationBusy = true;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Failed to delete custom word!");
+ }
+
+ Test(success);
+ m_DeleteCustomWordTested = true;
+ }
+
+ private void HandleGetCustomWord(WordData word, string customData)
+ {
+ if (!string.IsNullOrEmpty(customData))
+ Log.Debug("TestSpeechToText", "custom data: {0}", customData);
+
+ if (word != null)
+ Log.Debug("TestSpeechToText", "WordData - word: {0} | sounds like[0]: {1} | display as: {2} | source[0]: {3}", word.word, word.sounds_like[0], word.display_as, word.source[0]);
+
+ Test(word != null);
+ m_GetCustomWordTested = true;
+ }
+
+ private void OnCheckCustomizationStatus(Customization customization, string customData)
+ {
+ if(customization != null)
+ {
+ Log.Debug("TestSpeechToText", "Customization status: {0}", customization.status);
+ if (customization.status != "ready" && customization.status != "available")
+ Runnable.Run(CheckCustomizationStatus(customData, 5f));
+ else
+ m_IsCustomizationBusy = false;
+ }
+ else
+ {
+ Log.Debug("TestSpeechToText", "Check customization status failed!");
+ }
+ }
+
+ private IEnumerator CheckCustomizationStatus(string customizationID, float delay = 0.1f)
+ {
+ Log.Debug("TestSpeechToText", "Checking customization status in {0} seconds...", delay.ToString());
+ yield return new WaitForSeconds(delay);
+
+ // passing customizationID in custom data
+ m_SpeechToText.GetCustomization(OnCheckCustomizationStatus, customizationID, customizationID);
+ }
+ }
}
diff --git a/Scripts/Utilities/Constants.cs b/Scripts/Utilities/Constants.cs
index 8b0d22ac8..ae64d78d5 100755
--- a/Scripts/Utilities/Constants.cs
+++ b/Scripts/Utilities/Constants.cs
@@ -66,7 +66,7 @@ public static class Resources
public static class String
{
///
- public const string VERSION = "watson-developer-cloud-unity-sdk-0.10.0";
+ public const string VERSION = "watson-developer-cloud-unity-sdk-0.11.0";
///
public const string DEBUG_DISPLAY_QUALITY = "Quality: {0}";
}
diff --git a/Scripts/Utilities/Utility.cs b/Scripts/Utilities/Utility.cs
index 78ffafc4e..b44f96f32 100755
--- a/Scripts/Utilities/Utility.cs
+++ b/Scripts/Utilities/Utility.cs
@@ -488,8 +488,6 @@ public static byte[] Color32ArrayToByteArray(Color32[] colors)
return null;
}
-
-
- #endregion
- }
+ #endregion
+ }
}
diff --git a/Scripts/Widgets/DataTypes.cs b/Scripts/Widgets/DataTypes.cs
index 8cf9409a8..38cf5662d 100755
--- a/Scripts/Widgets/DataTypes.cs
+++ b/Scripts/Widgets/DataTypes.cs
@@ -440,7 +440,7 @@ public SpeechToTextData()
/// Data constructor.
///
/// The SpeechToText results.
- public SpeechToTextData(SpeechResultList result)
+ public SpeechToTextData(SpeechRecognitionEvent result)
{
Results = result;
}
@@ -455,7 +455,7 @@ public override string GetName()
///
/// The Result object.
///
- public SpeechResultList Results { get; set; }
+ public SpeechRecognitionEvent Results { get; set; }
///
/// Gets a value indicating whether the result text is final.
@@ -465,9 +465,9 @@ public bool IsFinal
{
get{
bool isFinal = false;
- if (Results != null && Results.Results.Length > 0)
+ if (Results != null && Results.results.Length > 0)
{
- isFinal = Results.Results[0].Final;
+ isFinal = Results.results[0].final;
}
return isFinal;
@@ -484,12 +484,12 @@ public string Text
get{
if (string.IsNullOrEmpty(_Text))
{
- if (Results != null && Results.Results.Length > 0)
+ if (Results != null && Results.results.Length > 0)
{
- SpeechResult speechResult = Results.Results[0];
- if (speechResult.Alternatives != null && speechResult.Alternatives.Length > 0)
+ SpeechRecognitionResult speechResult = Results.results[0];
+ if (speechResult.alternatives != null && speechResult.alternatives.Length > 0)
{
- _Text = speechResult.Alternatives[0].Transcript;
+ _Text = speechResult.alternatives[0].transcript;
}
}
}
diff --git a/Scripts/Widgets/LanguageTranslatorWidget.cs b/Scripts/Widgets/LanguageTranslatorWidget.cs
old mode 100644
new mode 100755
index 4b6659186..b1c21ebfd
--- a/Scripts/Widgets/LanguageTranslatorWidget.cs
+++ b/Scripts/Widgets/LanguageTranslatorWidget.cs
@@ -177,7 +177,7 @@ private void OnSpeechInput(Data data)
{
SpeechToTextData speech = data as SpeechToTextData;
if (speech != null && speech.Results.HasFinalResult())
- Translate(speech.Results.Results[0].Alternatives[0].Transcript);
+ Translate(speech.Results.results[0].alternatives[0].transcript);
}
private void OnGetLanguages(Languages languages)
diff --git a/Scripts/Widgets/NaturalLanguageClassifierWidget.cs b/Scripts/Widgets/NaturalLanguageClassifierWidget.cs
old mode 100644
new mode 100755
index cf894e11f..5bb10f8eb
--- a/Scripts/Widgets/NaturalLanguageClassifierWidget.cs
+++ b/Scripts/Widgets/NaturalLanguageClassifierWidget.cs
@@ -271,11 +271,11 @@ private void OnGetClassifier(Classifier classifier)
private void OnRecognize(Data data)
{
- SpeechResultList result = ((SpeechToTextData)data).Results;
+ SpeechRecognitionEvent result = ((SpeechToTextData)data).Results;
if (result.HasFinalResult())
{
- string text = result.Results[0].Alternatives[0].Transcript;
- double textConfidence = result.Results[0].Alternatives[0].Confidence;
+ string text = result.results[0].alternatives[0].transcript;
+ double textConfidence = result.results[0].alternatives[0].confidence;
Log.Debug("NaturalLanguageClassifierWidget", "OnRecognize: {0} ({1:0.00})", text, textConfidence);
EventManager.Instance.SendEvent("OnDebugMessage", string.Format("{0} ({1:0.00})", text, textConfidence));
diff --git a/Scripts/Widgets/SpeechDisplayWidget.cs b/Scripts/Widgets/SpeechDisplayWidget.cs
old mode 100644
new mode 100755
index 554a428ad..453a96e2e
--- a/Scripts/Widgets/SpeechDisplayWidget.cs
+++ b/Scripts/Widgets/SpeechDisplayWidget.cs
@@ -67,8 +67,8 @@ private void OnSpeechInput(Data data)
{
if (m_Output != null || m_OutputAsInputField != null)
{
- SpeechResultList result = ((SpeechToTextData)data).Results;
- if (result != null && result.Results.Length > 0)
+ SpeechRecognitionEvent result = ((SpeechToTextData)data).Results;
+ if (result != null && result.results.Length > 0)
{
string outputTextWithStatus = "";
string outputText = "";
@@ -87,30 +87,30 @@ private void OnSpeechInput(Data data)
if (m_OutputAsInputField != null && m_ContinuousText)
outputText = m_PreviousOutputText;
- foreach (var res in result.Results)
+ foreach (var res in result.results)
{
- foreach (var alt in res.Alternatives)
+ foreach (var alt in res.alternatives)
{
- string text = alt.Transcript;
+ string text = alt.transcript;
if (m_Output != null)
{
- m_Output.text = string.Concat(outputTextWithStatus, string.Format("{0} ({1}, {2:0.00})\n", text, res.Final ? "Final" : "Interim", alt.Confidence));
+ m_Output.text = string.Concat(outputTextWithStatus, string.Format("{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence));
}
if (m_OutputAsInputField != null)
{
- if (!res.Final || alt.Confidence > m_MinConfidenceToShow)
+ if (!res.final || alt.confidence > m_MinConfidenceToShow)
{
m_OutputAsInputField.text = string.Concat(outputText, " ", text);
if (m_OutputStatus != null)
{
- m_OutputStatus.text = string.Format("{0}, {1:0.00}", res.Final ? "Final" : "Interim", alt.Confidence);
+ m_OutputStatus.text = string.Format("{0}, {1:0.00}", res.final ? "Final" : "Interim", alt.confidence);
}
}
}
- if (!res.Final)
+ if (!res.final)
m_TimeAtLastInterim = Time.time;
}
diff --git a/Scripts/Widgets/SpeechToTextWidget.cs b/Scripts/Widgets/SpeechToTextWidget.cs
old mode 100644
new mode 100755
index 3bde2fc51..3b140312f
--- a/Scripts/Widgets/SpeechToTextWidget.cs
+++ b/Scripts/Widgets/SpeechToTextWidget.cs
@@ -165,15 +165,15 @@ private void OnLanguage(Data data)
}
}
- private void OnGetModels( SpeechModel [] models )
+ private void OnGetModels( Model [] models )
{
if ( models != null )
{
- SpeechModel bestModel = null;
+ Model bestModel = null;
foreach( var model in models )
{
- if ( model.Language.StartsWith( m_Language )
- && (bestModel == null || model.Rate > bestModel.Rate) )
+ if ( model.language.StartsWith( m_Language )
+ && (bestModel == null || model.rate > bestModel.rate) )
{
bestModel = model;
}
@@ -181,30 +181,30 @@ private void OnGetModels( SpeechModel [] models )
if ( bestModel != null )
{
- Log.Status( "SpeechToTextWidget", "Selecting Recognize Model: {0} ", bestModel.Name );
- m_SpeechToText.RecognizeModel = bestModel.Name;
+ Log.Status( "SpeechToTextWidget", "Selecting Recognize Model: {0} ", bestModel.name );
+ m_SpeechToText.RecognizeModel = bestModel.name;
}
}
}
- private void OnRecognize(SpeechResultList result)
+ private void OnRecognize(SpeechRecognitionEvent result)
{
m_ResultOutput.SendData( new SpeechToTextData( result ) );
- if (result != null && result.Results.Length > 0)
+ if (result != null && result.results.Length > 0)
{
if ( m_Transcript != null )
m_Transcript.text = "";
- foreach( var res in result.Results )
+ foreach( var res in result.results )
{
- foreach( var alt in res.Alternatives )
+ foreach( var alt in res.alternatives )
{
- string text = alt.Transcript;
+ string text = alt.transcript;
if ( m_Transcript != null )
m_Transcript.text += string.Format( "{0} ({1}, {2:0.00})\n",
- text, res.Final ? "Final" : "Interim", alt.Confidence );
+ text, res.final ? "Final" : "Interim", alt.confidence );
}
}
}