Esempio n. 1
0
        public VoiceClip GetVoiceClip(string name)
        {
            VoiceClip clip = voiceClips[name] as VoiceClip;

            if (clip == null)
            {
                foreach (DictionaryEntry tmp in voiceClips)
                {
                    VoiceClip tmpClp = tmp.Value as VoiceClip;

                    if (tmpClp.text == name || (name.Length > 2 && name.Substring(2) == tmpClp.text))
                    {
                        return(tmpClp);
                    }

                    try
                    {
                        if (tmpClp.text.Replace('\"', '\'') == name.Replace('\"', '\'') || (name.Length > 2 && name.Substring(2) == tmpClp.text))
                        {
                            return(tmpClp);
                        }
                    }
                    catch { }
                }
            }

            return(clip);
        }
Esempio n. 2
0
 public void QueueVoiceLine(Emotion face, VoiceClip clip, Priority prio, float time = float.PositiveInfinity)
 {
     clipsToPlay.Add(new NextClip()
     {
         face     = face,
         clip     = clip,
         priority = prio,
         timeLeft = time,
     });
 }
Esempio n. 3
0
        public void LoadVoiceovers(string AudioClipFolder)
        {
            audioClips = Resources.LoadAll <AudioClip>("audio/voices-01/" + AudioClipFolder);

            foreach (AudioClip audioClip in audioClips)
            {
                string prefix = "audio/voices-01/" + AudioClipFolder + "/";

                TextAsset   text        = Resources.Load(prefix + audioClip.name + "_txt") as TextAsset;
                LipSyncData lipSyncData = Resources.Load <LipSyncData>(prefix + audioClip.name);


                string txt = "";

                if (text != null)
                {
                    txt = text.text;
                }
                TextAsset phonemes = Resources.Load("audio/voices-01/" + AudioClipFolder + "/" + audioClip.name + "_phonemes") as TextAsset;

                VoiceClip voiceClip = new VoiceClip();
                voiceClip.name = audioClip.name;

                CharacterHead.Moods mood = CharacterHead.Moods.Neutral;

                if (lipSyncData != null)
                {
                    voiceClip.phonemes = GetPhonemesFromLipSyncData(lipSyncData, audioClip.length);

                    Debug.Log("Lipsync Data " + voiceClip.phonemes);
                }
                else
                {
                    voiceClip.phonemes = GetPhonemesFromMohoText(phonemes.text);
                }

                voiceClip.audioClip = audioClip;
                voiceClip.mood      = mood;

                GameObject audioSource = (GameObject.Instantiate(audioSourceTemplate) as Transform).gameObject;

                audioSource.name = voiceClip.name;
                audioSource.GetComponent <AudioSource>().clip = voiceClip.audioClip;
                audioSource.transform.parent = audioSourceFolder;

                voiceClip.audioSource             = audioSource.GetComponent <AudioSource>();
                voiceClip.audioSource.playOnAwake = false;

                voiceClip.volume = 1;

                voiceClips.Add(voiceClip.name, voiceClip);
            }
        }
Esempio n. 4
0
        public VoiceClip GetDefaultVoiceClip(string name)
        {
            VoiceClip cliptmp = GetVoiceClip("default_Neutral");

            VoiceClip clip = new VoiceClip();

            clip.audioClip     = cliptmp.audioClip;
            clip.audioSource   = cliptmp.audioSource;
            clip.interruptFlag = cliptmp.interruptFlag;
            clip.mood          = cliptmp.mood;
            clip.name          = cliptmp.name;
            clip.phonemes      = cliptmp.phonemes;
            //OBSOLETE-TOMIclip.text = LocalizationManager.GetTranslation(name);

            clip.audioSource.volume = 0;

            clip.mood = GetMoodFromString(clip.text, out clip.text);

            return(clip);
        }
    public AudioClip[] GetVoiceClips(DoruPersonality p, VoiceClip type)
    {
        //Debug.Log("Personality: " + p + "| Voice line: " + type);
        NpcVoiceClip[] voiceClips = genericVoiceClips;
        switch (p)
        {
        case DoruPersonality.Generic:
            voiceClips = genericVoiceClips;
            break;

        case DoruPersonality.Sensual:
            /*if (sensualVoiceClips.Length > 0) voiceClips = sensualVoiceClips;
             * else */voiceClips = genericVoiceClips;
            break;

        case DoruPersonality.Shy:
            /*if (shyVoiceClips.Length > 0) voiceClips = shyVoiceClips;
             * else */voiceClips = genericVoiceClips;
            break;
        }
        //Debug.Log("voiceClips: " + voiceClips);

        for (int i = 0; i < voiceClips.Length; i++)
        {
            if (voiceClips[i].type == type)
            {
                //Debug.Log("Success");
                if (voiceClips[i].clips.Length > 0)
                {
                    return(voiceClips[i].clips);
                }
                else
                {
                    return(genericVoiceClips[i].clips);
                }
            }
        }
        return(null);
    }
Esempio n. 6
0
        protected virtual IEnumerator RunLipSyncProc(string charName, AudioSource src, AudioClip audioClip, int lineID, string message)
        {
            this.interruptFlag = false;
            IsTalking          = true;

            string      currentMode = "idle";
            LipSyncData lipSyncData = Resources.Load <LipSyncData>("Lipsync/" + charName + "/" + charName + lineID.ToString());

            if (audioClip == null || lipSyncData == null)
            {
                float fakeClipLength = 3f;
                float startTime      = Time.time;

                fakeClipLength = message.Length * 0.1f;

                // Simulate a talk cycle
                string[] talkCycle = { "AI", "AI", "O", "AI", "E", "AI", "O", "U" };
                int      i         = 0;
                while (Time.time - startTime < fakeClipLength && !interruptFlag)
                {
                    //if(character != null && !character.isTalking) interruptFlag = true;
                    string ph = talkCycle[i % talkCycle.Length];
                    i++;
                    ShowPhoneme(ph);
                    yield return(new WaitForSeconds(.09f));
                }

                ShowPhoneme("MBP");
            }
            else
            {
                VoiceClip voiceClip = new VoiceClip();
                voiceClip.name = audioClip.name;
                voiceClip.text = "text not needed here";
                CharacterHead.Moods mood = CharacterHead.Moods.Neutral;

                SetArmAnimationEnabled(true);

                if (lipSyncData != null)
                {
                    voiceClip.phonemes  = GetPhonemesFromLipSyncData(lipSyncData, audioClip.length);
                    voiceClip.audioClip = audioClip;
                    voiceClip.mood      = mood;

                    CharacterHead.Moods currentMood = CharacterHead.Moods.Neutral;

                    while (src.isPlaying && !interruptFlag)
                    {
                        //if(character != null && !character.isTalking) interruptFlag = true;
                        float time = src.time;

                        bool change = false;

                        voiceClip.phonemes.GetMode(time /*+ pause*/, ref currentMode, ref change);

                        if (change)
                        {
                            ChangeTalkMode(currentMode);
                        }

                        change = false;

                        voiceClip.phonemes.GetMood(time /*+ pause*/, ref currentMood, ref change);

                        if (change)
                        {
                            ChangeMood(currentMood);
                        }

                        string ph = voiceClip.phonemes.GetPhoneme(time /*+ pause*/).Trim();

                        ShowPhoneme(ph);

                        yield return(new WaitForSeconds(1 / 60f));
                    }
                }
            }

            ChangeTalkMode("idle");

            ShowPhoneme("MBP");

            ChangeMood(CharacterHead.Moods.Neutral);

            IsTalking = false;

            animator.SetBool("talking", false);

            ResetArmAnimationStatus();

            yield return(null);
        }
Esempio n. 7
0
        public IEnumerator PlayVoiceFake(VoiceClip clip, ShowPhoneme showPhonemeFunction, ChangeMood changeMoodFunction, ChangeMode changeModeFunction, CharacterHead head, int textCharactersInLine = 32, float volume = 1)
        {
            //		Debug.Log ("PlayVoice " + textCharactersInLine);

            string text = clip.text;

            float pause = 1f / 24f;

            //		Debug.Log ("Talk: " + name);

            string[] textLines = StringSplit(text, textCharactersInLine * 2).ToArray();

            CharacterHead.Moods currentMood;
            string currentMode;

            currentMood = clip.mood;
            if (changeMoodFunction != null)
            {
                changeMoodFunction(currentMood);
                Debug.Log("PlayVoiceFake Mood Change: " + currentMood);
            }
            float startTime = Time.time;

            if (textLines.Length > 0)
            {
                float textLineCount = textLines.Length;

                int currentTextLine = 0;

                ShowText(textLines[0], head, textCharactersInLine);

                currentMood = clip.mood;
                currentMode = clip.mode;

                clip.audioSource.Play();

                currentVoicePlaying = clip.audioSource;

                //clip.audioSource.volume = !(isMutedSound || Global.muteSpeech) ? volume : 0;

                while ((Time.time - startTime) < clip.duration)
                {
                    float time = (Time.time - startTime);// clip.audioSource.time;

                    float textLine = textLineCount * (time / clip.duration);

                    int c = (int)Mathf.Floor(textLine);

                    if (c != currentTextLine && c < textLines.Length)
                    {
                        currentTextLine = c;
                        ShowText(textLines[currentTextLine], head, textCharactersInLine);
                    }

                    bool change = false;

                    clip.phonemes.GetMode(time + pause, ref currentMode, ref change);

                    if (change)
                    {
                        changeModeFunction(currentMode);
                    }

                    change = false;

                    clip.phonemes.GetMood(time + pause, ref currentMood, ref change);

                    if (change)
                    {
                        changeMoodFunction(currentMood);
                    }

                    string ph = clip.phonemes.GetPhoneme(time + pause).Trim();
                    showPhonemeFunction(ph);

                    /*
                     *                  if(ph == "O" || ph == "U") // HACK: FOR O and U, hold the phoneme longer
                     *                  {
                     *                          yield return new WaitForSeconds(pause*4);
                     *                  }
                     *                  else
                     */
                    if (clip.interruptFlag)
                    {
                        Debug.Log("interrupt flag " + clip.interruptFlag);
                        clip.audioSource.Stop();

                        break;
                    }

                    yield return(new WaitForSeconds(pause));
                }

                showPhonemeFunction("MBP");
                changeMoodFunction(CharacterHead.Moods.Neutral);

                currentVoicePlaying = null;
                //Global.characterDialogText.SetText("");
            }

            //Global.player.ChangeMood(CharacterHead.Moods.Neutral);

            yield return(null);
        }