// Refresh private static IEnumerator RefreshPhraseData(TTSService service, TTSDiskCacheSettings cacheSettings, TTSVoiceSettings voiceSettings, TTSPreloadPhraseData phraseData, Action <float> onProgress, Action <string> onComplete) { RefreshPhraseData(service, cacheSettings, voiceSettings, phraseData); yield return(null); onComplete?.Invoke(string.Empty); }
// Refresh phrase data public static void RefreshPhraseData(TTSService service, TTSDiskCacheSettings cacheSettings, TTSVoiceSettings voiceSettings, TTSPreloadPhraseData phraseData) { // Get voice settings if (service == null || voiceSettings == null || string.IsNullOrEmpty(phraseData.textToSpeak)) { phraseData.clipID = string.Empty; phraseData.downloaded = false; phraseData.downloadProgress = 0f; return; } if (cacheSettings == null) { cacheSettings = new TTSDiskCacheSettings() { DiskCacheLocation = TTSDiskCacheLocation.Preload }; } // Get phrase data phraseData.clipID = service.GetClipID(phraseData.textToSpeak, voiceSettings); // Check if file exists string path = service.GetDiskCachePath(phraseData.textToSpeak, phraseData.clipID, voiceSettings, cacheSettings); phraseData.downloaded = File.Exists(path); phraseData.downloadProgress = phraseData.downloaded ? 1f : 0f; }
// Preload voice text private static IEnumerator PreloadPhraseData(TTSService service, TTSDiskCacheSettings cacheSettings, TTSVoiceSettings voiceSettings, TTSPreloadPhraseData phraseData, Action <float> onProgress, Action <string> onComplete) { // Begin running bool running = true; // Download string log = string.Empty; service.DownloadToDiskCache(phraseData.textToSpeak, string.Empty, voiceSettings, cacheSettings, delegate(TTSClipData data, string path, string error) { // Set phrase data phraseData.clipID = data.clipID; phraseData.downloaded = string.IsNullOrEmpty(error); // Failed if (!phraseData.downloaded) { log += $"\n-{voiceSettings.settingsID} Preload Failed: {phraseData.textToSpeak}"; } // Next running = false; }); // Wait for running to complete while (running) { //Debug.Log($"Preload Wait: {voiceSettings.settingsID} - {phraseData.textToSpeak}"); yield return(null); } // Invoke onComplete?.Invoke(log); }