Exemplo n.º 1
0
        public static AutoSyncLanguageModel Load(string languageName)
        {
            string[] assets = AssetDatabase.FindAssets("t:AutoSyncLanguageModel");

            var settings = LipSyncEditorExtensions.GetProjectFile();

            if (settings == null)
            {
                return(null);
            }
            if (settings.phonemeSet == null)
            {
                return(null);
            }

            if (assets.Length > 0)
            {
                foreach (string guid in assets)
                {
                    AutoSyncLanguageModel model = AssetDatabase.LoadAssetAtPath <AutoSyncLanguageModel>(AssetDatabase.GUIDToAssetPath(guid));
                    if (model.language == languageName)
                    {
                        if (model.recommendedPhonemeSet != settings.phonemeSet.scriptingName && !string.IsNullOrEmpty(model.recommendedPhonemeSet))
                        {
                            if (!EditorUtility.DisplayDialog("Wrong Phoneme Set", "Warning: You are using the '" + settings.phonemeSet.scriptingName + "' Phoneme Set, and this language model is designed for use with '" + model.recommendedPhonemeSet + "'. This may not provide usable results, are you sure you want to continue?", "Yes", "No"))
                            {
                                return(null);
                            }
                        }
                        return(model);
                    }
                }
            }

            return(null);
        }
        public override void OnWizardGUI()
        {
            EditorGUI.BeginDisabledGroup(locked);
            switch (currentStep)
            {
            case 1:
                EditorGUILayout.HelpBox("This wizard will guide you through setting up AutoSync for your current project.\nCheck the auto-detected settings below (based on your system) and press 'Continue' to apply them.", MessageType.Info);
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Operating System", detectedOS);
                EditorGUILayout.HelpBox("SoX Sound Exchange is a third-party library that AutoSync can use to convert audio files to the correct format to be processed, making it compatible with a wider range of files.", MessageType.Info);
                soXPath = LipSyncEditorExtensions.DrawPathField("SoX Sound Exchange Path", soXPath, "ls_debug", "Find SoX Sound Exchange");
                EditorGUILayout.Space();
                LipSyncEditorExtensions.BeginPaddedHorizontal(20);
                if (GUILayout.Button("Auto-Detect Path", GUILayout.MaxWidth(250), GUILayout.Height(20)))
                {
                    DetectPaths();
                }
                LipSyncEditorExtensions.EndPaddedHorizontal(20);
                EditorGUILayout.Space();
                if (osLin)
                {
                    EditorGUILayout.HelpBox("The Linux editor is not officially supported at this time, some AutoSync features may still work, but the PocketSphinx module and SoX audio conversion are not supported.", MessageType.Error);
                    EditorGUILayout.Space();
                }
                else if (osMac)
                {
                    EditorGUILayout.HelpBox("Note that the included PocketSphinx module is not supported on most versions of macOS. Follow the instructions on the next screen for more info.", MessageType.Warning);
                    EditorGUILayout.Space();
                }

                break;

            case 2:
                GUILayout.Label("Installed Modules", EditorStyles.boldLabel);
                GUILayout.BeginHorizontal();
                GUILayout.Space(10);
                GUILayout.BeginVertical();
                if (moduleInfos != null)
                {
                    for (int i = 0; i < moduleInfos.Count; i++)
                    {
                        GUILayout.Label(moduleInfos[i].displayName);
                    }
                }
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
                EditorGUILayout.Space();
                if (mfaFound)
                {
                    EditorGUILayout.HelpBox("It looks like all recommended modules are installed. Feel free to download others from the Extension Window.", MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox("In order to keep the initial download size down, only the legacy PocketSphinx module is included. For best results (and compatibility with macOS) we recommend downloading the Montreal Forced Aligner module, which makes use of both the audio clip and a text transcript to create much more accurate lip-sync animation.", MessageType.Info);
                    if (GUILayout.Button("Start Downloading Montreal Forced Aligner", GUILayout.Height(25)))
                    {
                        locked      = true;
                        canContinue = false;

                        if (osMac)
                        {
                            RDExtensionWindow.RequestInstall("AutoSync Montreal Forced Aligner Module (Mac)");
                        }
                        else if (!osLin)
                        {
                            RDExtensionWindow.RequestInstall("AutoSync Montreal Forced Aligner Module (Win)");
                        }
                    }
                }

                break;

            case 3:
                EditorGUILayout.HelpBox("This section contains setup for individual modules. You may want to run this wizard again later if you download additional modules that require setup, or you may configure them manually from the AutoSync settings page in the Clip Editor.", MessageType.Info);
                EditorGUILayout.Space();

                for (int i = 0; i < moduleInfos.Count; i++)
                {
                    if (moduleInfos[i].moduleSettingsType != null)
                    {
                        GUILayout.Label(moduleInfos[i].displayName + " Setup", EditorStyles.boldLabel);
                        settingsObjects[i].DrawSetupWizardSection();
                        EditorGUILayout.Space();
                    }
                }
                break;
            }
            EditorGUI.EndDisabledGroup();

            if (locked)
            {
                GUILayout.Space(10);
                if (GUILayout.Button("Continue Wizard Anyway", GUILayout.Height(30)))
                {
                    locked      = false;
                    canContinue = true;
                    RemoveNotification();
                }

                ShowNotification(new GUIContent("Please allow the download to finish + install before returning to this wizard."));
            }
        }
Exemplo n.º 3
0
        private void OnGUI()
        {
            GUILayout.Space(20);

            EditorGUI.BeginDisabledGroup(setup.Clip && !soXAvailable);
            LipSyncEditorExtensions.BeginPaddedHorizontal();
            durationMode = GUILayout.Toolbar(durationMode, new string[] { "Duration", "Start + End Times" });
            LipSyncEditorExtensions.EndPaddedHorizontal();
            GUILayout.Space(10);
            if (durationMode == 0)
            {
                willTrim = length != setup.FileLength;
                TimeSpan time = TimeSpan.FromSeconds(length);

                int minutes      = time.Minutes;
                int seconds      = time.Seconds;
                int milliseconds = time.Milliseconds;

                GUILayout.BeginHorizontal(GUILayout.MaxWidth(280));
                EditorGUI.BeginChangeCheck();
                GUILayout.Label("Duration");
                minutes = EditorGUILayout.IntField(minutes);
                GUILayout.Label("m", EditorStyles.miniLabel);
                seconds = EditorGUILayout.IntField(seconds);
                GUILayout.Label("s", EditorStyles.miniLabel);
                milliseconds = EditorGUILayout.IntField(milliseconds);
                GUILayout.Label("ms", EditorStyles.miniLabel);
                if (EditorGUI.EndChangeCheck())
                {
                    float nl = (minutes * 60) + seconds + (milliseconds / 1000f);
                    if (setup.Clip)
                    {
                        nl = Mathf.Clamp(nl, 0, setup.Clip.length);
                    }
                    length = nl;
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                willTrim = start > 0 || end < setup.FileLength;
                TimeSpan startTime = TimeSpan.FromSeconds(start);
                TimeSpan endTime   = TimeSpan.FromSeconds(end);

                int startMinutes      = startTime.Minutes;
                int startSeconds      = startTime.Seconds;
                int startMilliseconds = startTime.Milliseconds;
                int endMinutes        = endTime.Minutes;
                int endSeconds        = endTime.Seconds;
                int endMilliseconds   = endTime.Milliseconds;

                GUILayout.BeginHorizontal(GUILayout.MaxWidth(280));
                EditorGUI.BeginChangeCheck();
                GUILayout.Label("Start Time");
                startMinutes = EditorGUILayout.IntField(startMinutes);
                GUILayout.Label("m", EditorStyles.miniLabel);
                startSeconds = EditorGUILayout.IntField(startSeconds);
                GUILayout.Label("s", EditorStyles.miniLabel);
                startMilliseconds = EditorGUILayout.IntField(startMilliseconds);
                GUILayout.Label("ms", EditorStyles.miniLabel);
                if (EditorGUI.EndChangeCheck())
                {
                    float ns = (startMinutes * 60) + startSeconds + (startMilliseconds / 1000f);
                    ns    = Mathf.Clamp(ns, 0, end);
                    start = ns;
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(GUILayout.MaxWidth(280));
                EditorGUI.BeginChangeCheck();
                GUILayout.Label("End Time");
                endMinutes = EditorGUILayout.IntField(endMinutes);
                GUILayout.Label("m", EditorStyles.miniLabel);
                endSeconds = EditorGUILayout.IntField(endSeconds);
                GUILayout.Label("s", EditorStyles.miniLabel);
                endMilliseconds = EditorGUILayout.IntField(endMilliseconds);
                GUILayout.Label("ms", EditorStyles.miniLabel);
                if (EditorGUI.EndChangeCheck())
                {
                    float ne = (endMinutes * 60) + endSeconds + (endMilliseconds / 1000f);
                    if (setup.Clip)
                    {
                        ne = Mathf.Clamp(ne, start, setup.Clip.length);
                    }
                    end = ne;
                }
                GUILayout.EndHorizontal();
            }
            EditorGUI.EndDisabledGroup();
            adjustMarkersAnimBool.target = willTrim;
            if (EditorGUILayout.BeginFadeGroup(adjustMarkersAnimBool.faded))
            {
                adjustMarkers = EditorGUILayout.Toggle("Keep Marker Times", adjustMarkers);
            }
            EditorGUILayout.EndFadeGroup();

            if (setup.Clip && !soXAvailable)
            {
                EditorGUILayout.HelpBox("Cannot Change duration as SoX is not available to trim the audio. Follow the included guide to set up SoX.", MessageType.Warning);
            }

            GUILayout.Space(10);
            GUILayout.Label("Transcript");
            scroll     = GUILayout.BeginScrollView(scroll, GUILayout.ExpandHeight(true));
            transcript = GUILayout.TextArea(transcript, GUILayout.ExpandHeight(true));
            GUILayout.EndScrollView();
            GUILayout.FlexibleSpace();
            GUILayout.Space(20);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(willTrim && setup.Clip ? "Trim & Save" : "Save", GUILayout.MinWidth(100), GUILayout.Height(20)))
            {
                setup.Transcript = transcript;
                if (willTrim)
                {
                    if (durationMode == 0)
                    {
                        if (setup.Clip)
                        {
                            TrimClip(0, length);
                        }
                        else
                        {
                            if (adjustMarkers)
                            {
                                AdjustMarkers(0, length);
                            }
                        }

                        setup.FileLength = length;
                    }
                    else
                    {
                        if (setup.Clip)
                        {
                            TrimClip(start, end - start);
                        }
                        else
                        {
                            if (adjustMarkers)
                            {
                                AdjustMarkers(start, end - start);
                            }
                        }

                        setup.FileLength = end - start;
                    }
                }

                setup.changed          = true;
                setup.previewOutOfDate = true;
                Close();
            }
            GUILayout.Space(10);
            if (GUILayout.Button("Cancel", GUILayout.MinWidth(100), GUILayout.Height(20)))
            {
                Close();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(20);
        }