1717
1818using UnityEngine ;
1919using IBM . Watson . DeveloperCloud . Services . TextToSpeech . v1 ;
20+ using IBM . Watson . DeveloperCloud . Logging ;
2021
2122public class ExampleTextToSpeech : MonoBehaviour
2223{
@@ -26,9 +27,116 @@ public class ExampleTextToSpeech : MonoBehaviour
2627
2728 void Start ( )
2829 {
29- m_TextToSpeech . Voice = VoiceType . en_US_Allison ;
30- m_TextToSpeech . ToSpeech ( m_TestString , HandleToSpeechCallback , true ) ;
31- }
30+ LogSystem . InstallDefaultReactors ( ) ;
31+
32+ //// Get Voices
33+ //Log.Debug("ExampleTextToSpeech", "Attempting to get voices.");
34+ //m_TextToSpeech.GetVoices(OnGetVoices);
35+
36+ //// Get Voice
37+ ////string selectedVoice = "en-US_AllisonVoice";
38+ //Log.Debug("ExampleTextToSpeech", "Attempting to get voice {0}.", VoiceType.en_US_Allison);
39+ //m_TextToSpeech.GetVoice(OnGetVoice, VoiceType.en_US_Allison);
40+
41+ //// Get Pronunciation
42+ //string testWord = "Watson";
43+ //Log.Debug("ExampleTextToSpeech", "Attempting to get pronunciation of {0}", testWord);
44+ //m_TextToSpeech.GetPronunciation(OnGetPronunciation, testWord, VoiceType.en_US_Allison);
45+
46+ // Get Customizations
47+ //Log.Debug("ExampleTextToSpeech", "Attempting to get a list of customizations");
48+ //m_TextToSpeech.GetCustomizations(OnGetCustomizations);
49+
50+ // Create Customization
51+ //Log.Debug("ExampleTextToSpeech", "Attempting to create a customization");
52+ //string customizationName = "unity-example-customization";
53+ //string customizationLanguage = "en-US";
54+ //string customizationDescription = "A text to speech voice customization created within Unity.";
55+ //m_TextToSpeech.CreateCustomization(OnCreateCustomization, customizationName, customizationLanguage, customizationDescription);
56+
57+ // Delete Customization
58+ //Log.Debug("ExampleTextToSpeech", "Attempting to delete a customization");
59+ //string customizationIdentifierToDelete = "1476ea80-5355-4911-ac99-ba39162a2d34";
60+ //if (!m_TextToSpeech.DeleteCustomization(OnDeleteCustomization, customizationIdentifierToDelete))
61+ // Log.Debug("ExampleTextToSpeech", "Failed to delete custom voice model!");
62+
63+ // Get Customization
64+ //Log.Debug("ExampleTextToSpeech", "Attempting to get a customization");
65+ //string customizationIdentifierToGet = "1476ea80-5355-4911-ac99-ba39162a2d34";
66+ //if (!m_TextToSpeech.GetCustomization(OnGetCustomization, customizationIdentifierToGet))
67+ // Log.Debug("ExampleTextToSpeech", "Failed to get custom voice model!");
68+
69+ // Update Customization
70+ Log . Debug ( "ExampleTextToSpeech" , "Attempting to update a customization" ) ;
71+ Word word0 = new Word ( ) ;
72+ word0 . word = "hello" ;
73+ word0 . translation = "hullo" ;
74+ Word word1 = new Word ( ) ;
75+ word1 . word = "goodbye" ;
76+ word1 . translation = "gbye" ;
77+ Word word2 = new Word ( ) ;
78+ word2 . word = "hi" ;
79+ word2 . translation = "ohiooo" ;
80+ Word [ ] words = { word0 , word1 , word2 } ;
81+ CustomVoiceUpdate customVoiceUpdate = new CustomVoiceUpdate ( ) ;
82+ customVoiceUpdate . words = words ;
83+ customVoiceUpdate . description = "My updated description" ;
84+ customVoiceUpdate . name = "My updated name" ;
85+ string customizationIdToUpdate = "1476ea80-5355-4911-ac99-ba39162a2d34" ;
86+ if ( ! m_TextToSpeech . UpdateCustomization ( OnUpdateCustomization , customizationIdToUpdate , customVoiceUpdate ) )
87+ Log . Debug ( "ExampleTextToSpeech" , "Failed to update customization!" ) ;
88+
89+ // Get Customization Words
90+ //Log.Debug("ExampleTextToSpeech", "Attempting to get a customization's words");
91+ //string customIdentifierToGetWords = "1476ea80-5355-4911-ac99-ba39162a2d34";
92+ //if (!m_TextToSpeech.GetCustomizationWords(OnGetCustomizationWords, customIdentifierToGetWords))
93+ // Log.Debug("ExampleTextToSpeech", "Failed to get {0} words!", customIdentifierToGetWords);
94+
95+ // Add Customization Words
96+ //Log.Debug("ExampleTextToSpeech", "Attempting to add words to a customization");
97+ //string customIdentifierToAddWords = "1476ea80-5355-4911-ac99-ba39162a2d34";
98+ //Words words = new Words();
99+ //Word word0 = new Word();
100+ //word0.word = "bananna";
101+ //word0.translation = "bunanna";
102+ //Word word1 = new Word();
103+ //word1.word = "orange";
104+ //word1.translation = "arange";
105+ //Word word2 = new Word();
106+ //word2.word = "tomato";
107+ //word2.translation = "tomahto";
108+ //Word[] wordArray = { word0, word1, word2 };
109+ //words.words = wordArray;
110+ //if (!m_TextToSpeech.AddCustomizationWords(OnAddCustomizationWords, customIdentifierToAddWords, words))
111+ // Log.Debug("ExampleTextToSpeech", "Failed to add words to {0}!", customIdentifierToAddWords);
112+
113+ // Delete Customization Word
114+ //Log.Debug("ExampleTextToSpeech", "Attempting to delete customization word from custom voice model.");
115+ //string customIdentifierToDeleteWord = "1476ea80-5355-4911-ac99-ba39162a2d34";
116+ //string wordToDelete = "goodbye";
117+ //if (!m_TextToSpeech.DeleteCustomizationWord(OnDeleteCustomizationWord, customIdentifierToDeleteWord, wordToDelete))
118+ // Log.Debug("ExampleTextToSpeech", "Failed to delete {0} from {1}!", wordToDelete, customIdentifierToDeleteWord);
119+
120+ // Get Customization Word
121+ //Log.Debug("ExampleTextToSpeech", "Attempting to get the translation of a custom voice model's word.");
122+ //string customIdentifierToGetWord = "1476ea80-5355-4911-ac99-ba39162a2d34";
123+ //string customIdentifierWord = "hello";
124+ //if (!m_TextToSpeech.GetCustomizationWord(OnGetCustomizationWord, customIdentifierToGetWord, customIdentifierWord))
125+ // Log.Debug("ExampleTextToSpeech", "Failed to get the translation of {0} from {1}!", customIdentifierWord, customIdentifierToGetWord);
126+
127+ // Add Customization Word - This is not working. The PUT method is not supported by Unity.
128+ //Log.Debug("ExampleTextToSpeech", "Attempting to add a single word and translation to a custom voice model.");
129+ //string customIdentifierToAddWordAndTranslation = "1476ea80-5355-4911-ac99-ba39162a2d34";
130+ //string word = "grasshopper";
131+ //string translation = "guhrasshoppe";
132+ //if (!m_TextToSpeech.AddCustomizationWord(OnAddCustomizationWord, customIdentifierToAddWordAndTranslation, word, translation))
133+ // Log.Debug("ExampleTextToSpeech", "Failed to add {0}/{1} to {2}!", word, translation, customIdentifierToAddWordAndTranslation);
134+
135+
136+ //m_TextToSpeech.Voice = VoiceType.en_US_Allison;
137+ //m_TextToSpeech.ToSpeech(m_TestString, HandleToSpeechCallback, true);
138+
139+ }
32140
33141 void HandleToSpeechCallback ( AudioClip clip )
34142 {
@@ -49,4 +157,118 @@ private void PlayClip(AudioClip clip)
49157 GameObject . Destroy ( audioObject , clip . length ) ;
50158 }
51159 }
160+
161+ private void OnGetVoices ( Voices voices )
162+ {
163+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetVoices-----" ) ;
164+ foreach ( Voice voice in voices . voices )
165+ Log . Debug ( "ExampleTextToSpeech" , "Voice | name: {0} | gender: {1} | language: {2} | customizable: {3} | description: {4}." , voice . name , voice . gender , voice . language , voice . customizable , voice . description ) ;
166+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetVoices-----" ) ;
167+ }
168+
169+ private void OnGetVoice ( Voice voice )
170+ {
171+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetVoice-----" ) ;
172+ Log . Debug ( "ExampleTextToSpeech" , "Voice | name: {0} | gender: {1} | language: {2} | customizable: {3} | description: {4}" , voice . name , voice . gender , voice . language , voice . customizable , voice . description ) ;
173+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetVoice-----" ) ;
174+ }
175+
176+ private void OnGetPronunciation ( Pronunciation pronunciation )
177+ {
178+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetPronunciation-----" ) ;
179+ Log . Debug ( "ExampleTextToSpeech" , "Pronunciation: {0}." , pronunciation . pronunciation ) ;
180+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetPronunciation-----" ) ;
181+ }
182+
183+ private void OnGetCustomizations ( Customizations customizations , string data )
184+ {
185+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomizations-----" ) ;
186+ if ( data != default ( string ) )
187+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
188+ foreach ( Customization customization in customizations . customizations )
189+ Log . Debug ( "ExampleTextToSpeech" , "Customization: name: {0} | customization_id: {1} | language: {2} | description: {3} | owner: {4} | created: {5} | last modified: {6}" , customization . name , customization . customization_id , customization . language , customization . description , customization . owner , customization . created , customization . last_modified ) ;
190+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomizations-----" ) ;
191+ }
192+
193+ private void OnCreateCustomization ( CustomizationID customizationID , string data )
194+ {
195+ Log . Debug ( "ExampleTextToSpeech" , "-----OnCreateCustomization-----" ) ;
196+ if ( data != default ( string ) )
197+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
198+ Log . Debug ( "ExampleTextToSpeech" , "CustomizationID: id: {0}." , customizationID . customization_id ) ;
199+ Log . Debug ( "ExampleTextToSpeech" , "-----OnCreateCustomization-----" ) ;
200+ }
201+
202+ private void OnDeleteCustomization ( bool success , string data )
203+ {
204+ Log . Debug ( "ExampleTextToSpeech" , "-----OnDeleteCustomization-----" ) ;
205+ if ( data != default ( string ) )
206+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
207+ Log . Debug ( "ExampleTextToSpeech" , "Success: {0}." , success ) ;
208+ Log . Debug ( "ExampleTextToSpeech" , "-----OnDeleteCustomization-----" ) ;
209+ }
210+
211+ private void OnGetCustomization ( Customization customization , string data )
212+ {
213+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomization-----" ) ;
214+ if ( data != default ( string ) )
215+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
216+ Log . Debug ( "ExampleTextToSpeech" , "Customization: name: {0} | customization_id: {1} | language: {2} | description: {3} | owner: {4} | created: {5} | last modified: {6}" , customization . name , customization . customization_id , customization . language , customization . description , customization . owner , customization . created , customization . last_modified ) ;
217+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomization-----" ) ;
218+ }
219+
220+ private void OnUpdateCustomization ( bool success , string data )
221+ {
222+ Log . Debug ( "ExampleTextToSpeech" , "-----OnUpdateCustomization-----" ) ;
223+ if ( data != default ( string ) )
224+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
225+ Log . Debug ( "ExampleTextToSpeech" , "Success: {0}." , success ) ;
226+ Log . Debug ( "ExampleTextToSpeech" , "-----OnUpdateCustomization-----" ) ;
227+ }
228+
229+ private void OnGetCustomizationWords ( Words words , string data )
230+ {
231+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomizationWords-----" ) ;
232+ if ( data != default ( string ) )
233+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
234+ foreach ( Word word in words . words )
235+ Log . Debug ( "ExampleTextToSpeech" , "Word: {0} | Translation: {1}." , word . word , word . translation ) ;
236+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomizationWords-----" ) ;
237+ }
238+
239+ private void OnAddCustomizationWords ( bool success , string data )
240+ {
241+ Log . Debug ( "ExampleTextToSpeech" , "-----OnAddCustomizationWords-----" ) ;
242+ if ( data != default ( string ) )
243+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
244+ Log . Debug ( "ExampleTextToSpeech" , "Success: {0}." , success ) ;
245+ Log . Debug ( "ExampleTextToSpeech" , "-----OnAddCustomizationWords-----" ) ;
246+ }
247+
248+ private void OnDeleteCustomizationWord ( bool success , string data )
249+ {
250+ Log . Debug ( "ExampleTextToSpeech" , "-----OnDeleteCustomizationWord-----" ) ;
251+ if ( data != default ( string ) )
252+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
253+ Log . Debug ( "ExampleTextToSpeech" , "Success: {0}." , success ) ;
254+ Log . Debug ( "ExampleTextToSpeech" , "-----OnDeleteCustomizationWord-----" ) ;
255+ }
256+
257+ private void OnGetCustomizationWord ( Translation translation , string data )
258+ {
259+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomizationWord-----" ) ;
260+ if ( data != default ( string ) )
261+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
262+ Log . Debug ( "ExampleTextToSpeech" , "Translation: {0}." , translation . translation ) ;
263+ Log . Debug ( "ExampleTextToSpeech" , "-----OnGetCustomizationWord-----" ) ;
264+ }
265+
266+ private void OnAddCustomizationWord ( bool success , string data )
267+ {
268+ Log . Debug ( "ExampleTextToSpeech" , "-----OnAddCustomizationWord-----" ) ;
269+ if ( data != default ( string ) )
270+ Log . Debug ( "ExampleTextToSpeech" , "data: {0}" , data ) ;
271+ Log . Debug ( "ExampleTextToSpeech" , "Success: {0}." , success ) ;
272+ Log . Debug ( "ExampleTextToSpeech" , "-----OnAddCustomizationWord-----" ) ;
273+ }
52274}
0 commit comments