Beispiel #1
0
        public static void CreateCharacterSynthesis(CharacterSynthesis characterSynthesis)
        {
            var payload     = "{\"character_synthesis\": " + JsonUtility.ToJson(characterSynthesis) + "}";
            var response    = NewClient().UploadString($"{GetApiBaseUrl()}/character_syntheses", payload);
            var apiResponse = JsonUtility.FromJson <ApiResponse <CharacterSynthesis> >(response);

            switch (apiResponse.status)
            {
            case 201:
                characterSynthesis.id           = apiResponse.result.id;
                characterSynthesis.created_at   = apiResponse.result.created_at;
                characterSynthesis.text_id      = apiResponse.result.text_id;
                characterSynthesis.synthesis_id = apiResponse.result.synthesis_id;
                characterSynthesis.synthesis_result_file_url = apiResponse.result.synthesis_result_file_url;
                break;

            case 422:
                Debug.LogError($"API errors: {apiResponse.GetErrorsAsJson()}");
                characterSynthesis.SetErrors(apiResponse.GetErrorsDictionnary());
                break;

            default:
                throw new WebException($"API error {apiResponse.status}");
            }
        }
 private void MakeMain(CharacterSynthesis characterSynthesis)
 {
     // a false value means we don't need to refresh the window
     if (text.SetMainCharacterSynthesisId(characterSynthesis.id))
     {
         FetchData();
         DownloadMain();
     }
 }
        // ------------------------------------------------------------------------
        // METHODS
        // ------------------------------------------------------------------------

        public void FetchData()
        {
            text = Api.GetText(text_id);
            mainCharacterSynthesis = text.GetMainCharacterSynthesis();
            characterSyntheses     = Api.GetCharacterSyntheses(
                text,
                LATEST_CHARACTER_SYNTHESES_COUNT + 1
                );
        }
        private void Resynthesize()
        {
            CharacterSynthesis newCharacterSynthesis = new CharacterSynthesis();

            newCharacterSynthesis.synthesis_text     = text.main_synthesis_text;
            newCharacterSynthesis.synthesis_modifier = text.main_synthesis_modifier;
            newCharacterSynthesis.character_id       = text.main_character_id;
            newCharacterSynthesis.text_slug          = text.slug;
            Router.NewCharacterSynthesis(newCharacterSynthesis);
        }
        public static void NewCharacterSynthesis(CharacterSynthesis model = null)
        {
            NewCharacterSynthesisWindow window = new NewCharacterSynthesisWindow();

            window.FetchData();
            if (model != null)
            {
                window.SetCharacterSynthesis(model);
            }
            window.Show();
        }
Beispiel #6
0
        public CharacterSynthesis GetMainCharacterSynthesis()
        {
            var character_synthesis = new CharacterSynthesis();

            character_synthesis.id                        = main_character_synthesis_id;
            character_synthesis.is_main                   = true;
            character_synthesis.text_id                   = id;
            character_synthesis.text_slug                 = slug;
            character_synthesis.character_id              = main_character_id;
            character_synthesis.character_name            = main_character_name;
            character_synthesis.synthesis_id              = main_synthesis_id;
            character_synthesis.synthesis_modifier        = main_synthesis_modifier;
            character_synthesis.synthesis_result_file_url = main_synthesis_result_file_url;
            character_synthesis.synthesis_text            = main_synthesis_text;
            character_synthesis.created_at                = main_synthesis_created_at;
            return(character_synthesis);
        }
        private async Task PerformSynthesis(int idx)
        {
            await Task.Run(() => {
                try
                {
                    CharacterSynthesis characterSynthesis = characterSyntheses[idx];

                    if (!replaceExistingFiles && characterSynthesis.ResultFileExists())
                    {
                        Debug.Log($"Audio file for {characterSynthesis.text_slug} already existing: skip it");
                        exportSkipped++;
                    }
                    else
                    {
                        if (characterSynthesis.Create())
                        {
                            if (characterSynthesis.DownloadResultFile())
                            {
                                Logger.Log("Synthesis done");
                            }
                            else
                            {
                                Debug.LogError("result file couldn't be downloaded");
                                exportErrors.Add($"Audio file for {characterSynthesis.text_slug} couldn't be downloaded");
                            }
                        }
                        else
                        {
                            Debug.LogError($"CharacterSynthesis errors: {characterSynthesis.GetErrorsAsJson()}");
                            exportErrors.Add($"Synthesis error for {characterSynthesis.text_slug}");
                        }
                    }
                } catch (Exception e) {
                    exportErrors.Add($"Synthesis error for line {idx+1}: {e}");
                    Debug.LogError($"ERROR: {e}");
                }
            });
        }
        private void ReadImportFile()
        {
            if (importFileRead)
            {
                return;
            }

            importFileRead = true;
            int line_idx = 0;

            characterSyntheses = new List <CharacterSynthesis>();

            string importFileContent = null;

            switch (importMethod)
            {
            case ImportMethod.UnityAssets:
                importFileContent = importAsset.text;
                break;

            case ImportMethod.CSV:
                StreamReader reader = new StreamReader(importPath);
                importFileContent = reader.ReadToEnd();
                reader.Close();
                break;
            }

            foreach (Dictionary <string, string> line in DictionaryCSVReader.FromString(importFileContent))
            {
                line_idx++;

                // checks
                if (line_idx == 1)
                {
                    if (!line.ContainsKey("text"))
                    {
                        Debug.LogError("Column \"text\" not found in file");
                        importFileErrors.Add("Column \"text\" not found in file");
                    }
                    if (!line.ContainsKey("character_id"))
                    {
                        Debug.LogError("Column \"character_id\" not found in file");
                        importFileErrors.Add("Column \"character_id\" not found in file");
                    }
                    if (!line.ContainsKey("slug"))
                    {
                        Debug.LogError("Column \"slug\" not found in file");
                        importFileErrors.Add("Column \"slug\" not found in file");
                    }
                    if (!line.ContainsKey("modifier"))
                    {
                        Debug.LogError("Column \"modifier\" not found in file");
                        importFileErrors.Add("Column \"modifier\" not found in file");
                    }
                    if (importFileErrors.Count > 0)
                    {
                        return;
                    }
                }

                // find character
                Character character = FindCharacter(line["character_id"]);
                if (character == null)
                {
                    string error = $"Unknown character with ID or name {line["character_id"]} on line {line_idx}";
                    Debug.LogError(error);
                    importFileErrors.Add(error);
                    return;
                }

                // synthesis line
                CharacterSynthesis characterSynthesis = new CharacterSynthesis();
                characterSynthesis.synthesis_text     = line["text"];
                characterSynthesis.synthesis_modifier = line["modifier"];
                characterSynthesis.character_id       = character.id;
                characterSynthesis.text_slug          = line["slug"];
                characterSynthesis.SetImportFileLine(line_idx);
                characterSyntheses.Add(characterSynthesis);
            }
        }
 protected void PlayOther(CharacterSynthesis characterSynthesis)
 {
     PlayRemoteAudio(characterSynthesis.synthesis_result_file_url);
 }
 protected void PlayMain(CharacterSynthesis characterSynthesis)
 {
     PlayLocalAudio(characterSynthesis.GetResultFileAbsolutePath());
 }
Beispiel #11
0
 public void SetCharacterSynthesis(CharacterSynthesis newCharacterSynthesis)
 {
     characterSynthesis = newCharacterSynthesis;
 }