Skip to content

Commit 48a2ee0

Browse files
committed
examples for custom words
1 parent 89c4c01 commit 48a2ee0

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,38 @@ private void TestAddCustomCorpus(string customizationID, string corpusName, bool
122122
m_SpeechToText.AddCustomCorpus(HandleAddCustomCorpus, customizationID, corpusName, allowOverwrite, trainingDataPath);
123123
}
124124

125+
private void TestGetCustomWords()
126+
{
127+
Log.Debug("ExampleSpeechToText", "Attempting to get custom words.");
128+
m_SpeechToText.GetCustomWords(OnGetCustomWords, m_CreatedCustomizationID);
129+
}
130+
131+
private void TestAddCustomWordsPath(string customizationID, string wordsJsonPath)
132+
{
133+
Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words json path {1}", customizationID, wordsJsonPath);
134+
m_SpeechToText.AddCustomWords(OnAddCustomWords, customizationID, wordsJsonPath);
135+
}
136+
137+
private void TestAddCustomWordsWordsObject(string customizationID, Words words)
138+
{
139+
Log.Debug("ExampleSpeechToText", "Attempting to add custom words in customization {0} using Words object", customizationID);
140+
m_SpeechToText.AddCustomWords(OnAddCustomWords, customizationID, words);
141+
}
142+
143+
private void TestDeleteCustomWord(string customizationID, string word)
144+
{
145+
Log.Debug("ExampleSpeechToText", "Attempting to delete custom word {1} in customization {0}", customizationID, word);
146+
m_SpeechToText.DeleteCustomWord(OnDeleteCustomWord, customizationID, word);
147+
}
148+
149+
private void TestGetCustomWord(string customizationID, string word)
150+
{
151+
Log.Debug("ExampleSpeechToText", "Attempting to get custom word {1} in customization {0}", customizationID, word);
152+
m_SpeechToText.GetCustomWord(OnGetCustomWord, customizationID, word);
153+
}
154+
155+
156+
125157
private void HandleGetModels(Model[] models)
126158
{
127159
if (models != null)
@@ -369,4 +401,68 @@ private void HandleAddCustomCorpus(bool success, string customData)
369401
Log.Debug("ExampleSpeechToText", "Failed to delete custom corpus!");
370402
}
371403
}
404+
405+
private void OnGetCustomWords(WordsList wordList, string customData)
406+
{
407+
if (!string.IsNullOrEmpty(customData))
408+
Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
409+
410+
if(wordList != null)
411+
{
412+
if (wordList.words != null && wordList.words.Length > 0)
413+
{
414+
foreach (WordData word in wordList.words)
415+
Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as);
416+
}
417+
else
418+
{
419+
Log.Debug("ExampleSpeechToText", "No custom words found!");
420+
}
421+
}
422+
else
423+
{
424+
Log.Debug("ExampleSpeechToText", "Failed to get custom words!");
425+
}
426+
}
427+
428+
private void OnAddCustomWords(bool success, string customData)
429+
{
430+
if (!string.IsNullOrEmpty(customData))
431+
Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
432+
433+
if (success)
434+
{
435+
Log.Debug("ExampleSpeechToText", "AddCustomWOrds() succeeded!");
436+
437+
}
438+
else
439+
{
440+
Log.Debug("ExampleSpeechToText", "Failed to add custom words!");
441+
}
442+
}
443+
444+
private void OnDeleteCustomWord(bool success, string customData)
445+
{
446+
if (!string.IsNullOrEmpty(customData))
447+
Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
448+
449+
if (success)
450+
{
451+
Log.Debug("ExampleSpeechToText", "DeleteCustomWord() succeeded!");
452+
453+
}
454+
else
455+
{
456+
Log.Debug("ExampleSpeechToText", "Failed to delete custom word!");
457+
}
458+
}
459+
460+
private void OnGetCustomWord(WordData word, string customData)
461+
{
462+
if (!string.IsNullOrEmpty(customData))
463+
Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
464+
465+
if(word != null)
466+
Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as);
467+
}
372468
}

Scripts/Services/SpeechToText/DataModels.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ public class WordsList
595595
/// <summary>
596596
/// Information about each word in the custom model's words resource. The array is empty if the custom model has no words.
597597
/// </summary>
598-
public WordData words { get; set; }
598+
public WordData[] words { get; set; }
599599
}
600600

601601
/// <summary>

Scripts/Services/SpeechToText/SpeechToText.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ private void OnAddCustomWordsResp(RESTConnector.Request req, RESTConnector.Respo
16891689
}
16901690
#endregion
16911691

1692-
#region Delete Custom Words
1692+
#region Delete Custom Word
16931693
/// <summary>
16941694
/// This callback is used by the DeleteCustomWord() function.
16951695
/// </summary>

0 commit comments

Comments
 (0)