void OnTTSInit(string message) { int response = int.Parse(message); if (isInitialize == false) { switch (response) { case TTSManager.SUCCESS: isInitialize = true; if (TTSManager.IsInitialized()) { for (int i = 0; i < TTSManager.GetAvailableLanguages().Count; i++) { if (TTSManager.GetAvailableLanguages()[i].Name == languages.ToString()) { TTSManager.SetLanguage(TTSManager.GetAvailableLanguages()[i]); break; } } } break; case TTSManager.ERROR: //_initializeError = true; break; } } }
void OnTTSInit(string message) { int response = int.Parse(message); switch (response) { case TTSManager.SUCCESS: if (TTSManager.IsLanguageAvailable(TTSManager.GERMAN)) { Debug.Log("[TextToSpeechManager] Initialized and german language set."); TTSManager.SetLanguage(TTSManager.GERMAN); status = Status.Initialized; if (EventInitialized != null) { EventInitialized(); } return; } else { Debug.LogError("[TextToSpeechManager] German lange is not available. Available languages:"); foreach (var locale in TTSManager.GetAvailableLanguages()) { Debug.LogError(" - " + locale.Language + " / " + locale.Name); } } break; case TTSManager.ERROR: Debug.Log("[TextToSpeechManager] Initialization failed."); break; default: Debug.Log("[TextToSpeechManager] Initialization failed with unknown response: " + response); break; } status = Status.Error; if (EventInitializationErrorOrUnsupported != null) { EventInitializationErrorOrUnsupported(); } }
void OnTTSInit(string message) { int response = int.Parse(message); switch (response) { case TTSManager.SUCCESS: List <TTSManager.Locale> l = TTSManager.GetAvailableLanguages(); _localeStrings = new string[l.Count]; for (int i = 0; i < _localeStrings.Length; ++i) { _localeStrings [i] = l [i].Name; } break; case TTSManager.ERROR: _initializeError = true; break; } }
// Use this for initialization void Start() { // Screen.sleepTimeout = SleepTimeout.NeverSleep; TTSManager.Initialize(transform.name, "OnTTSInit"); if (TTSManager.IsInitialized()) { if (_localeStrings != null && _localeStrings.Length > 0) { //_selectedLocale = GUILayout.SelectionGrid(_selectedLocale, _localeStrings, 3); TTSManager.SetLanguage(TTSManager.GetAvailableLanguages()[_selectedLocale]); TTSManager.SetLanguage(TTSManager.ENGLISH); } // _pitch = TTSManager.SetPitch(_pitch, 0f, 2f); // _speechRate = TTSManager.SetSpeechRate(_speechRate, 0f, 2f); } }
void OnGUI() { float originalScreenWidth = 400f; float originalScreenHeight = (originalScreenWidth / Screen.width) * Screen.height; float scale = Screen.width / originalScreenWidth; Matrix4x4 svMat = GUI.matrix; // save current matrix GUI.matrix = Matrix4x4.Scale(Vector3.one * scale); GUI.skin.label.fontStyle = FontStyle.Bold; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUI.Label(new Rect(0f, 0f, originalScreenWidth, originalScreenHeight * 0.05f), "Android TTS Plugin"); GUI.skin.label.fontStyle = FontStyle.Normal; GUI.skin.label.alignment = TextAnchor.LowerLeft; GUI.skin.horizontalSliderThumb.fixedWidth = 30; GUI.skin.horizontalSliderThumb.fixedHeight = 30; Rect layoutRect = new Rect(originalScreenWidth * 0.05f, originalScreenHeight * 0.1f, originalScreenWidth * 0.9f, originalScreenHeight * 0.85f); GUILayout.BeginArea(layoutRect, GUI.skin.box); GUILayout.BeginVertical(); GUILayout.Space(25f); GUILayout.Label("Initialized: " + TTSManager.IsInitialized()); GUILayout.Space(35f); if (TTSManager.IsInitialized()) { _inputText = stringSource.getWords(); if (GUILayout.Button("Speak")) { TTSManager.Speak(_inputText, false, TTSManager.STREAM.Music, 1f, 0f, transform.name, "OnSpeechCompleted", "speech_" + (++_speechId)); } if (GUILayout.Button("Add to Queue")) { TTSManager.Speak(_inputText, true, TTSManager.STREAM.Music, 1f, 0f, transform.name, "OnSpeechCompleted", "speech_" + (++_speechId)); } if (GUILayout.Button("Synthesize to SDCard root folder")) { TTSManager.SynthesizeToFile(_inputText, "/mnt/sdcard/speech_" + (++_speechId) + ".wav", transform.name, "OnSynthesizeCompleted", "speech_" + (++_speechId)); } if (GUILayout.Button("Stop")) { TTSManager.Stop(); } GUILayout.Space(25f); GUILayout.Label("Device Supported Languages:"); if (_localeStrings != null && _localeStrings.Length > 0) { _selectedLocale = GUILayout.SelectionGrid(_selectedLocale, _localeStrings, 3); TTSManager.SetLanguage(TTSManager.GetAvailableLanguages() [_selectedLocale]); } GUILayout.Space(25f); GUILayout.BeginHorizontal(); GUILayout.Label("Pitch: "); _pitch = GUILayout.HorizontalSlider(_pitch, 0f, 2f); TTSManager.SetPitch(_pitch); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Speech Rate: "); _speechRate = GUILayout.HorizontalSlider(_speechRate, 0f, 2f); TTSManager.SetSpeechRate(_speechRate); GUILayout.EndHorizontal(); } else if (_initializeError) { GUI.contentColor = Color.red; GUILayout.Label("Error during initialization of TTS.\nIs it installed on your device?"); } GUILayout.EndVertical(); GUILayout.EndArea(); GUI.matrix = svMat; }