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 } }
protected override void Consume(Queue <char> InQueue) { char c = InQueue.Dequeue(); _ItemConsumed(c); // Console.WriteLine("Tokenizing input..."); if (state == TokenState.Letter) { if (HebrewChar.IsModifier(c)) { sb.Append(c); return; } else { LetterToken lt = new LetterToken(letter, sb.ToString()); this.Emit(lt); Console.WriteLine("tokenizer: Ate letter " + lt.Value); sb.Length = 0; state = TokenState.Neutral; } } switch (state) { case TokenState.Tag: if (c == '/') { state = TokenState.Neutral; TagToken tt = new TagToken(sb.ToString()); this.Emit(tt); Console.WriteLine("tokenizer: Ate tag " + tt.Type); sb.Length = 0; } else { sb.Append(c); } break; case TokenState.Neutral: if (HebrewChar.IsLetter(c) || (c == '/')) { if (sb.Length > 0) { Token t = new Token(sb.ToString()); this.Emit(t); Console.WriteLine("tokenizer: Ate neutral token " + t.Value); } if (c == '/') { state = TokenState.Tag; } else { letter = c; state = TokenState.Letter; } sb.Length = 0; } else if (HebrewChar.IsCantillation(c)) { CantillationToken ct = new CantillationToken(c.ToString()); this.Emit(ct); Console.WriteLine("tokenizer: Ate cantillation mark " + ct.Value); } else if (HebrewChar.IsPunctuation(c)) { PunctuationToken pt = new PunctuationToken(c.ToString()); this.Emit(pt); Console.WriteLine("tokenizer: Ate punctuation " + pt.Value); } else { sb.Append(c); } break; } }
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 } }