Exemplo n.º 1
0
        public static Phone Create(SpeechElement e)
        {
            if (e == null)
            {
                return(null);
            }
            if ((e is Vowel) && (e as Vowel).IsVowelIn(Vowels.Inaudible))
            {
                return(null);
            }
            if (e.Silent)
            {
                return(null);
            }
            Phone p = new Phone();

            if (e is Separator)
            {
                p.Symbol = "_";
                if (e.Latin == "׃")
                {
                    p.Duration = 260;
                }
                else if (e.Latin == ",")
                {
                    p.Duration = 60;
                }
                else if (e.Latin == ";")
                {
                    p.Duration = 120;
                }
                else if (e.Latin == ".")
                {
                    p.Duration = 250;
                }
                else if (e.Latin == "?")
                {
                    p.Duration = 250;
                }
                else if (e.Latin == "!")
                {
                    p.Duration = 250;
                }
                else if (e.Latin == "-")
                {
                    p.Duration = 90;
                }
            }
            else
            {
                p.Symbol = e.Latin;
                if (e is Phoneme)
                {
                    p.Sonority = (e as Phoneme).Sonority;
                }
            }
//			HebrewParser.Log.Qaryan.Core.WriteLine("Created phone "+p.Symbol);
            return(p);
        }
        protected override void Consume(Queue <Segment> InQueue)
        {
            if (InQueue.Count == 0)
            {
                return;
            }
            Segment seg = InQueue.Dequeue();

            _ItemConsumed(seg);
            Segment nextSeg = null;

            if (InQueue.Count > 0)
            {
                nextSeg = InQueue.Peek();
            }
            if (seg is SeparatorSegment)
            {
                if (HebrewChar.IsPunctuation((seg[0] as Separator).Latin[0]))
                {
                    Phone phn = Phone.Create(seg[0]);
                    if (phn == null)
                    {
                        phn = new Phone("_", 1);
                    }
                    Emit(phn);
                }
                firstStressInClause = true;
            }
            else if (seg is Word)
            {
                /*bool nextIsPunctuation = false;
                 * if (nextSeg is SeparatorSegment)
                 *  nextIsPunctuation = HebrewChar.IsPunctuation(nextSeg[0].Latin[0]);*/

                Word w = (Word)seg;

                bool          beforeStress     = true;
                SpeechElement HintStrongDagesh = null;
                for (int sylIndex = 0; sylIndex < w.Syllables.Count; sylIndex++)
                {
                    Syllable syl = w.Syllables[sylIndex];

                    bool stressed = syl.IsStressed;
                    if (beforeStress && stressed)
                    {
                        beforeStress = false;
                    }
                    bool beforeNucleus = true;

                    //bool heavySyl = ((syl.Coda == SyllableCoda.Closed) ^ ((syl.Nucleus!=null) && syl.Nucleus.IsVowelIn(Vowels.Long)));
                    //					bool sylStart=true;
                    //foreach (SpeechElement e in	w.Phonemes.GetRange(syl.Start,syl.End-syl.Start+1)) {
                    for (int elemIndex = 0; elemIndex < syl.Phonemes.Count; elemIndex++)
                    {
                        SpeechElement e     = syl.Phonemes[elemIndex];
                        Phone         phone = null;
//                        bool sylEnd = (elemIndex == syl.Phonemes.Count - 1);
                        if ((e is Consonant) && ((((Consonant)e).Flags & ConsonantFlags.StrongDagesh) != 0) && (e == HintStrongDagesh))
                        {
                            continue;
                        }

                        phone = Phone.Create(e);
                        if (phone == null)
                        {
                            continue;
                        }
                        phone.Context.SylIndex        = sylIndex;
                        phone.Context.SylReverseIndex = w.Syllables.Count - sylIndex - 1;
                        phone.Context.IsNucleus       = (syl.Nucleus == e);
                        phone.Context.IsAccented      = stressed;
                        if (nextSeg is SeparatorSegment)
                        {
                            phone.Context.NextSeparator = (nextSeg as SeparatorSegment)[0].Latin;
                        }
                        if (!stressed)
                        {
                            if (Options.Akanye)
                            {
                                if (phone.Symbol == "o")
                                {
                                    phone.Symbol = "a";
                                }
                            }
                            if (Options.Ikanye)
                            {
                                if (phone.Symbol == "e")
                                {
                                    phone.Symbol = "i";
                                }
                            }
                        }
                        else
                        {
                            phone.Context.AccentStrength = 1;
                        }
                        if (phone.PitchCurve.Count > 0)
                        {
                            phone.PitchCurve.Clear();
                        }

                        phone.Duration = 80;
                        if (e is Vowel)
                        {
                            Vowel v = (Vowel)e;
                            if (v.IsVowelIn(Vowels.VeryShort))
                            {
                                if (v.vowel == Vowels.AudibleSchwa)
                                {
                                    phone.Duration = 28;
                                }
                                else
                                {
                                    phone.Duration = 40;
                                }
                            }
                            else if (v.IsVowelIn(Vowels.Short))
                            {
                                phone.Duration = 90;
                            }
                            else if (v.IsVowelIn(Vowels.Long))
                            {
                                phone.Duration = 94;
                            }
                            else if (v.IsVowelIn(Vowels.VeryLong))
                            {
                                phone.Duration = 97;
                            }
                            if (v.IsVowelIn(Vowels.HighVowels))
                            {
                                phone.Duration += 25;
                            }
                            else
                            {
                                phone.Duration += 30;
                            }
                        }
                        else if (e is Consonant)
                        {
                            phone.Duration = (((Consonant)e).Sonority) * 1.6 + 60;
                        }
                        else
                        {
                            phone.Duration = 100;
                        }

                        if (stressed)
                        {
                            if (firstStressInClause)
                            {
                                firstStressInClause = false;
                            }
                            if (e == syl.Nucleus)
                            {
                                beforeNucleus = false;
                            }
                            phone.Duration *= 1;
                            if (beforeNucleus && (e is Consonant) && ((Consonant)e).IsLiquid)
                            {
                                phone.Duration *= 1.2;
                            }
                        }
                        else
                        {
                            if (e is Vowel)
                            {
                                if (beforeStress)
                                {
                                    phone.Duration *= 0.85;
                                }
                                else
                                {
                                    phone.Duration *= 0.9;
                                }
                            }
                        }
                        if ((e is Consonant) && ((((Consonant)e).Flags & ConsonantFlags.StrongDagesh) != 0))
                        {
                            HintStrongDagesh = e;
                            if (Options.DistinguishStrongDagesh)
                            {
                                phone.Duration *= 1.4;
                            }
                            else
                            {
                                phone.Duration *= 1.1F;
                            }
                        }

                        /* if ((!nextIsPunctuation) && !heavySyl)
                         *   phone.Duration *= 0.7;*/

                        //                        if ((nextSeg is SeparatorSegment) && (sylIndex == w.Syllables.Count - 1))
                        //                            phone.Duration *= 1.6;
                        Emit(phone);



                        //						sylStart=false;
                    }
                }

                /*					if (w.CantillationMarks.Contains('֑'))
                 *      silpr.Phones.Add(new Phone("_",200));*/
                #region cantillation stuff
                if (Options.SingCantillation)
                {
                    foreach (char ch in w.CantillationMarks)
                    {
                        int i = HebrewChar.DisjunctiveRank(ch), len = 0;

                        if (i < 5)
                        {
                            switch (i)
                            {
                            case 1:
                                len = 230;
                                break;

                            case 2:
                                len = 165;
                                break;

                            case 3:
                                len = 60;
                                break;

                            case 4:
                                len = 30;
                                break;
                            }
                            Emit(new Phone("_", len));
                        }
                    }
                }
                #endregion
            }
        }
Exemplo n.º 3
0
        protected override void Consume(Queue <Segment> InQueue)
        {
            if (InQueue.Count == 0)
            {
                return;
            }
            Segment seg = InQueue.Dequeue();

            _ItemConsumed(seg);
            Segment nextSeg = null;

            if (InQueue.Count > 0)
            {
                nextSeg = InQueue.Peek();
            }
            if (seg is SeparatorSegment)
            {
                if (HebrewChar.IsPunctuation((seg[0] as Separator).Latin[0]))
                {
                    Phone phn = Phone.Create(seg[0]);
                    if (phn == null)
                    {
                        phn = new Phone("_", 1);
                    }
                    Emit(phn);
                    Console.WriteLine("phonetizer: {0}", phn);
                }
                firstStressInClause = true;
            }
            else if (seg is Word)
            {
                Word w = (Word)seg;

                bool          beforeStress     = true;
                SpeechElement HintStrongDagesh = null;
                foreach (Syllable syl in w.Syllables)
                {
                    bool stressed = syl.IsStressed;
                    if (beforeStress && stressed)
                    {
                        beforeStress = false;
                    }
                    bool beforeNucleus = true;

//					bool sylStart=true;
                    foreach (SpeechElement e in     w.Phonemes.GetRange(syl.Start, syl.End - syl.Start + 1))
                    {
                        Phone phone  = null;
                        bool  sylEnd = (syl.Phonemes.IndexOf(e) == syl.Phonemes.Count - 1);
                        if ((e is Consonant) && ((((Consonant)e).Flags & ConsonantFlags.StrongDagesh) != 0) && (e == HintStrongDagesh))
                        {
                            continue;
                        }

                        phone = Phone.Create(e);
                        if (phone == null)
                        {
                            continue;
                        }
                        phone.Context.IsNucleus  = (syl.Nucleus == e);
                        phone.Context.IsAccented = stressed;
                        if (nextSeg is SeparatorSegment)
                        {
                            phone.Context.NextSeparator = (nextSeg as SeparatorSegment)[0].Latin;
                        }
                        if (!stressed)
                        {
                            if (Options.Akanye)
                            {
                                if (phone.Symbol == "o")
                                {
                                    phone.Symbol = "a";
                                }
                            }
                            if (Options.Ikanye)
                            {
                                if (phone.Symbol == "e")
                                {
                                    phone.Symbol = "i";
                                }
                            }
                        }
                        else
                        {
                            phone.Context.AccentStrength = 1;
                        }
                        if (phone.PitchCurve.Count > 0)
                        {
                            phone.PitchCurve.Clear();
                        }

                        phone.Duration = 80;
                        if (e is Vowel)
                        {
                            Vowel v = (Vowel)e;
                            if (v.IsVowelIn(Vowels.VeryShort))
                            {
                                phone.Duration = 28;                               //38
                            }
                            else if (v.IsVowelIn(Vowels.Short))
                            {
                                phone.Duration = 90;
                            }
                            else if (v.IsVowelIn(Vowels.Long))
                            {
                                phone.Duration = 94;
                            }
                            else if (v.IsVowelIn(Vowels.VeryLong))
                            {
                                phone.Duration = 97;
                            }
                            if (v.IsVowelIn(Vowels.HighVowels))
                            {
                                phone.Duration += 25;
                            }
                            else
                            {
                                phone.Duration += 30;
                            }
                        }
                        else if (e is Consonant)
                        {
                            phone.Duration = (((Consonant)e).Sonority) * 2.6 + 60;
                        }
                        else
                        {
                            phone.Duration = 100;
                        }

                        if (stressed)
                        {
                            if (firstStressInClause)
                            {
                                firstStressInClause = false;
                            }
                            if (e == syl.Nucleus)
                            {
                                beforeNucleus = false;
                            }
                            phone.Duration *= 1;
                            if (beforeNucleus && (e is Consonant) && ((Consonant)e).IsLiquid)
                            {
                                phone.Duration *= 1.2;
                            }
                        }
                        else
                        {
                            if (e is Vowel)
                            {
                                if (beforeStress)
                                {
                                    phone.Duration *= 0.5;
                                }
                                else
                                {
                                    phone.Duration *= 0.6;
                                }
                            }
                        }
                        if ((e is Consonant) && ((((Consonant)e).Flags & ConsonantFlags.StrongDagesh) != 0))
                        {
                            HintStrongDagesh = e;
                            if (Options.DistinguishStrongDagesh)
                            {
                                phone.Duration *= 1.4;
                            }
                            else
                            {
                                phone.Duration *= 1.1F;
                            }
                        }

                        Emit(phone);
                        Console.WriteLine("phonetizer: {0}", phone);



//						sylStart=false;
                    }
                }

                /*					if (w.CantillationMarks.Contains('֑'))
                 *              silpr.Phones.Add(new Phone("_",200));*/
                #region cantillation stuff
                if (Options.SingCantillation)
                {
                    foreach (char ch in w.CantillationMarks)
                    {
                        int i = HebrewChar.DisjunctiveRank(ch), len = 0;

                        if (i < 5)
                        {
                            switch (i)
                            {
                            case 1:
                                len = 230;
                                break;

                            case 2:
                                len = 165;
                                break;

                            case 3:
                                len = 60;
                                break;

                            case 4:
                                len = 30;
                                break;
                            }
                            Phone phone;
                            Emit(phone = new Phone("_", len));
                            Console.WriteLine("phonetizer: {0}", phone);
                        }
                    }
                }
                #endregion
            }
        }