public void StartProcessUnknownAttributes(object voice, ref FragmentState fragmentState, string sElement, List <SsmlXmlAttribute> extraAttributes) { foreach (SsmlXmlAttribute extraAttribute in extraAttributes) { _writer.WriteAttributeString(extraAttribute._prefix, extraAttribute._name, extraAttribute._ns, extraAttribute._value); } }
public void ProcessText(string text, object voice, ref FragmentState fragmentState, int position, bool fIgnore) { if (!fIgnore) { TtsEngineAction action = fragmentState.Action; if (_paragraphStarted) { fragmentState.Action = TtsEngineAction.StartParagraph; _speakInfo.AddText((TTSVoice)voice, new TextFragment(fragmentState)); _paragraphStarted = false; // Always add the start sentence. _sentenceStarted = true; } if (_sentenceStarted) { fragmentState.Action = TtsEngineAction.StartSentence; _speakInfo.AddText((TTSVoice)voice, new TextFragment(fragmentState)); _sentenceStarted = false; } fragmentState.Action = ActionTextFragment(action); _speakInfo.AddText((TTSVoice)voice, new TextFragment(fragmentState, text, _ssmlText, position, text.Length)); fragmentState.Action = action; } }
public void EndProcessUnknownAttributes(object voice, ref FragmentState fragmentState, string element, List <SsmlXmlAttribute> extraAttributes) { AddParseUnknownFragment(voice, ref fragmentState, string.Format(CultureInfo.InvariantCulture, "</{0}>", new object[1] { element })); }
public void StartProcessUnknownAttributes(object voice, ref FragmentState fragmentState, string sElement, List <SsmlXmlAttribute> extraAttributes) { // write all the additional namespace foreach (SsmlXmlAttribute attribute in extraAttributes) { _writer.WriteAttributeString(attribute._prefix, attribute._name, attribute._ns, attribute._value); } }
private void AddParseUnknownFragment(object voice, ref FragmentState fragmentState, string text) { TtsEngineAction action = fragmentState.Action; fragmentState.Action = TtsEngineAction.ParseUnknownTag; _speakInfo.AddText((TTSVoice)voice, new TextFragment(fragmentState, text)); fragmentState.Action = action; }
public void ProcessPhoneme(ref FragmentState fragmentState, AlphabetType alphabet, string ph, char[] phoneIds) { _writer.WriteStartElement("phoneme"); if (alphabet != AlphabetType.Ipa) { _writer.WriteAttributeString("alphabet", (alphabet == AlphabetType.Sapi) ? "x-microsoft-sapi" : "x-microsoft-ups"); } _writer.WriteAttributeString("ph", ph); }
public object ProcessTextBlock(bool isParagraph, object voice, ref FragmentState fragmentState, CultureInfo culture, bool newCulture, VoiceGender gender, VoiceAge age) { _writer.WriteStartElement(isParagraph ? "p" : "s"); if (culture != null) { _writer.WriteAttributeString("xml", "lang", null, culture.Name); } return(null); }
public void ProcessBreak(object voice, ref FragmentState fragmentState, EmphasisBreak eBreak, int time, bool fIgnore) { if (!fIgnore) { TtsEngineAction action = fragmentState.Action; fragmentState.Action = ActionTextFragment(fragmentState.Action); _speakInfo.AddText((TTSVoice)voice, new TextFragment(fragmentState)); fragmentState.Action = action; } }
public void ProcessPhoneme(ref FragmentState fragmentState, AlphabetType alphabet, string ph, char[] phoneIds) { _writer.WriteStartElement("phoneme"); if (alphabet != AlphabetType.Ipa) { _writer.WriteAttributeString("alphabet", alphabet == AlphabetType.Sapi ? "x-microsoft-sapi" : "x-microsoft-ups"); System.Diagnostics.Debug.Assert(alphabet == AlphabetType.Ups || alphabet == AlphabetType.Sapi); } _writer.WriteAttributeString("ph", ph); }
public void ProcessMark(object voice, ref FragmentState fragmentState, string name, bool fIgnore) { if (!fIgnore) { TtsEngineAction action = fragmentState.Action; fragmentState.Action = ActionTextFragment(fragmentState.Action); _speakInfo.AddText((TTSVoice)voice, new TextFragment(fragmentState, name)); fragmentState.Action = action; } }
public void ProcessUnknownElement(object voice, ref FragmentState fragmentState, XmlReader reader) { StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); xmlTextWriter.WriteNode(reader, false); xmlTextWriter.Close(); string text = stringWriter.ToString(); AddParseUnknownFragment(voice, ref fragmentState, text); }
public void StartProcessUnknownAttributes(object voice, ref FragmentState fragmentState, string element, List <SsmlXmlAttribute> extraAttributes) { StringBuilder sb = new(); sb.AppendFormat(CultureInfo.InvariantCulture, "<{0}", element); foreach (SsmlXmlAttribute attribute in extraAttributes) { sb.AppendFormat(CultureInfo.InvariantCulture, " {0}:{1}=\"{2}\" xmlns:{3}=\"{4}\"", attribute._prefix, attribute._name, attribute._value, attribute._prefix, attribute._ns); } sb.Append('>'); AddParseUnknownFragment(voice, ref fragmentState, sb.ToString()); }
public object ProcessTextBlock(bool isParagraph, object voice, ref FragmentState fragmentState, CultureInfo culture, bool newCulture, VoiceGender gender, VoiceAge age) { if (culture != null && newCulture) { _speakInfo.SetVoice(null, culture, gender, age, 1); } if (isParagraph) { _paragraphStarted = true; } else { _sentenceStarted = true; } return(_speakInfo.Voice); }
public void ProcessBreak(object voice, ref FragmentState fragmentState, EmphasisBreak eBreak, int time, bool fIgnore) { _writer.WriteStartElement("break"); if (time > 0 && eBreak == EmphasisBreak.None) { _writer.WriteAttributeString("time", time.ToString(CultureInfo.InvariantCulture) + "ms"); } else { string value = null; switch (eBreak) { case EmphasisBreak.None: value = "none"; break; case EmphasisBreak.ExtraWeak: value = "x-weak"; break; case EmphasisBreak.Weak: value = "weak"; break; case EmphasisBreak.Medium: value = "medium"; break; case EmphasisBreak.Strong: value = "strong"; break; case EmphasisBreak.ExtraStrong: value = "x-strong"; break; } if (!string.IsNullOrEmpty(value)) { _writer.WriteAttributeString("strength", value); } } }
public void ProcessUnknownElement(object voice, ref FragmentState fragmentState, XmlReader reader) { _writer.WriteNode(reader, false); }
public void ProcessSub(string alias, object voice, ref FragmentState fragmentState, int position, bool fIgnore) { ProcessText(alias, voice, ref fragmentState, position, fIgnore); }
public void ProcessPhoneme(ref FragmentState fragmentState, AlphabetType alphabet, string ph, char[] phoneIds) { fragmentState.Action = TtsEngineAction.Pronounce; fragmentState.Phoneme = _speakInfo.Voice.TtsEngine.ConvertPhonemes(phoneIds, alphabet); }
public void ProcessText(string text, object voice, ref FragmentState fragmentState, int position, bool fIgnore) { _writer.WriteString(text); }
public void EndProcessUnknownAttributes(object voice, ref FragmentState fragmentState, string sElement, List <SsmlXmlAttribute> extraAttributes) { }
internal static bool ToSapi(List <TextFragment> ssmlFrags, ref GCHandle sapiFragLast) { bool fFirst = true; for (int iFrag = ssmlFrags.Count - 1; iFrag >= 0; iFrag--) { TextFragment textFragment = ssmlFrags[iFrag]; // Remove the start and end paragraph fragments if (textFragment.State.Action == TtsEngineAction.StartParagraph || textFragment.State.Action == TtsEngineAction.StartSentence) { continue; } SPVTEXTFRAG sapiFrag = new(); // start with the text fragment sapiFrag.gcNext = fFirst ? new GCHandle() : sapiFragLast; sapiFrag.pNext = fFirst ? IntPtr.Zero : sapiFragLast.AddrOfPinnedObject(); sapiFrag.gcText = GCHandle.Alloc(textFragment.TextToSpeak, GCHandleType.Pinned); sapiFrag.pTextStart = sapiFrag.gcText.AddrOfPinnedObject(); sapiFrag.ulTextSrcOffset = textFragment.TextOffset; sapiFrag.ulTextLen = textFragment.TextLength; // State SPVSTATE sapiState = new(); FragmentState ssmlState = textFragment.State; sapiState.eAction = (SPVACTIONS)ssmlState.Action; sapiState.LangID = (short)ssmlState.LangId; sapiState.EmphAdj = ssmlState.Emphasis != 1 ? 0 : 1; if (ssmlState.Prosody != null) { sapiState.RateAdj = SapiRate(ssmlState.Prosody.Rate); sapiState.Volume = SapiVolume(ssmlState.Prosody.Volume); sapiState.PitchAdj.MiddleAdj = SapiPitch(ssmlState.Prosody.Pitch); } else { sapiState.Volume = 100; } sapiState.ePartOfSpeech = SPPARTOFSPEECH.SPPS_Unknown; // Set the silence if any if (sapiState.eAction == SPVACTIONS.SPVA_Silence) { sapiState.SilenceMSecs = SapiSilence(ssmlState.Duration, (EmphasisBreak)ssmlState.Emphasis); } // Set the phonemes if any if (ssmlState.Phoneme != null) { sapiState.eAction = SPVACTIONS.SPVA_Pronounce; sapiFrag.gcPhoneme = GCHandle.Alloc(ssmlState.Phoneme, GCHandleType.Pinned); sapiState.pPhoneIds = sapiFrag.gcPhoneme.AddrOfPinnedObject(); // Get rid of the text if phonemes are defined. This is to be compatible with existing // TTS engines. } else { sapiFrag.gcPhoneme = new GCHandle(); sapiState.pPhoneIds = IntPtr.Zero; } // Set the say-as if any if (ssmlState.SayAs != null) { string format = ssmlState.SayAs.Format; string interpretAs; switch (interpretAs = ssmlState.SayAs.InterpretAs) { case "spellout": case "spell-out": case "characters": case "letters": sapiState.eAction = SPVACTIONS.SPVA_SpellOut; break; case "time": case "date": if (!string.IsNullOrEmpty(format)) { interpretAs = interpretAs + ':' + format; } sapiState.Context.pCategory = SapiCategory(sapiFrag, interpretAs, null); break; default: sapiState.Context.pCategory = SapiCategory(sapiFrag, interpretAs, format); break; } } sapiFrag.State = sapiState; sapiFragLast = GCHandle.Alloc(sapiFrag, GCHandleType.Pinned); fFirst = false; } return(!fFirst); }
internal static bool ToSapi(List <TextFragment> ssmlFrags, ref GCHandle sapiFragLast) { bool flag = true; for (int num = ssmlFrags.Count - 1; num >= 0; num--) { TextFragment textFragment = ssmlFrags[num]; if (textFragment.State.Action != TtsEngineAction.StartParagraph && textFragment.State.Action != TtsEngineAction.StartSentence) { SPVTEXTFRAG sPVTEXTFRAG = new SPVTEXTFRAG(); sPVTEXTFRAG.gcNext = (flag ? default(GCHandle) : sapiFragLast); sPVTEXTFRAG.pNext = (flag ? IntPtr.Zero : sapiFragLast.AddrOfPinnedObject()); sPVTEXTFRAG.gcText = GCHandle.Alloc(textFragment.TextToSpeak, GCHandleType.Pinned); sPVTEXTFRAG.pTextStart = sPVTEXTFRAG.gcText.AddrOfPinnedObject(); sPVTEXTFRAG.ulTextSrcOffset = textFragment.TextOffset; sPVTEXTFRAG.ulTextLen = textFragment.TextLength; SPVSTATE state = default(SPVSTATE); FragmentState state2 = textFragment.State; state.eAction = (SPVACTIONS)state2.Action; state.LangID = (short)state2.LangId; state.EmphAdj = ((state2.Emphasis == 1) ? 1 : 0); if (state2.Prosody != null) { state.RateAdj = SapiRate(state2.Prosody.Rate); state.Volume = SapiVolume(state2.Prosody.Volume); state.PitchAdj.MiddleAdj = SapiPitch(state2.Prosody.Pitch); } else { state.Volume = 100; } state.ePartOfSpeech = SPPARTOFSPEECH.SPPS_Unknown; if (state.eAction == SPVACTIONS.SPVA_Silence) { state.SilenceMSecs = SapiSilence(state2.Duration, (EmphasisBreak)state2.Emphasis); } if (state2.Phoneme != null) { state.eAction = SPVACTIONS.SPVA_Pronounce; sPVTEXTFRAG.gcPhoneme = GCHandle.Alloc(state2.Phoneme, GCHandleType.Pinned); state.pPhoneIds = sPVTEXTFRAG.gcPhoneme.AddrOfPinnedObject(); } else { sPVTEXTFRAG.gcPhoneme = default(GCHandle); state.pPhoneIds = IntPtr.Zero; } if (state2.SayAs != null) { string format = state2.SayAs.Format; string text; switch (text = state2.SayAs.InterpretAs) { case "spellout": case "spell-out": case "characters": case "letters": state.eAction = SPVACTIONS.SPVA_SpellOut; break; case "time": case "date": if (!string.IsNullOrEmpty(format)) { text = text + ":" + format; } state.Context.pCategory = SapiCategory(sPVTEXTFRAG, text, null); break; default: state.Context.pCategory = SapiCategory(sPVTEXTFRAG, text, format); break; } } sPVTEXTFRAG.State = state; sapiFragLast = GCHandle.Alloc(sPVTEXTFRAG, GCHandleType.Pinned); flag = false; } } return(!flag); }
public void ProcessSub(string alias, object voice, ref FragmentState fragmentState, int position, bool fIgnore) { _writer.WriteStartElement("sub"); _writer.WriteAttributeString("alias", alias); }
public void ProcessMark(object voice, ref FragmentState fragmentState, string name, bool fIgnore) { _writer.WriteStartElement("mark"); _writer.WriteAttributeString("name", name); }