/// <summary> /// Dump the data in the phone. /// </summary> /// <param name="scriptSyllable">The script syllable to store the data dumped from the phones.</param> /// <param name="utt">The utterance.</param> /// <param name="syllable">The syllable which contains these phones.</param> /// <param name="phoneIndex">Phone index to mark the phone in the Utt.Phones.</param> /// <param name="unitIndex">Unit index to mark the unit in the Utt.Units.</param> /// <param name="f0StartIndex">F0 index to mark the start position in the F0s.</param> /// <param name="ttsEngine">The object ttsEngine to help to convert the Pos and get sentence id.</param> private static void DumpPhones(ScriptSyllable scriptSyllable, SP.TtsUtterance utt, SP.TtsSyllable syllable, ref int phoneIndex, ref int unitIndex, ref int f0StartIndex, SP.TtsEngine ttsEngine) { Debug.Assert(scriptSyllable != null, "ScriptSyllable should not be null"); Debug.Assert(utt != null, "Utt should not be null"); Debug.Assert(syllable != null, "Syllable should not be null"); Debug.Assert(phoneIndex >= 0, "PhoneIndex should not be less than 0"); Debug.Assert(f0StartIndex >= 0, "f0StartIndex should not be less than 0"); Debug.Assert(ttsEngine != null, "ttsEngine should not be null"); WuiManager wuiManager = null; if (utt.Segments.Count > 0) { int bestNodeIndex = (int)utt.UnitLattice.WucList[unitIndex].BestNodeIndex; wuiManager = ttsEngine.RUSVoiceDataManager.GetWuiManagerByUnitCostNode(utt.UnitLattice.WucList[unitIndex].WucNodeList[bestNodeIndex]); } // Go through each phone in the syllable. SP.TtsPhone phone = syllable.FirstPhone; while (phone != null) { // Dump the pronunciation of the phone. string phonePronunciation = Pronunciation.RemoveStress(phone.Pronunciation.ToLowerInvariant()).Trim(); // Remove the tone from the phone pronunciation if it exist. if (phone.Tone != 0) { phonePronunciation = Pronunciation.RemoveTone(phonePronunciation).Trim(); } ScriptPhone scriptPhone = new ScriptPhone(phonePronunciation); scriptPhone.Tone = phone.Tone.ToString(); scriptPhone.Stress = (TtsStress)phone.Stress; if (phone.Pronunciation != PronOfSilence) { if (wuiManager != null) { scriptPhone.SentenceId = wuiManager.GetSentenceId(utt.Segments[unitIndex].WaveUnitInfo); } if (phone.Unit != null) { scriptPhone.UnitIndex = (int)phone.Unit.UnitIndex; } } scriptPhone.Acoustics = new ScriptAcoustics(); // Dump the segments. if (utt.Segments.Count > 0 && !utt.Segments[unitIndex].Unit.UnitText.Equals(PronOfSilence) && !utt.Segments[unitIndex].Unit.UnitText.Equals(PronOfShortPause)) { scriptPhone.Acoustics.Duration = (int)utt.Segments[unitIndex].WaveUnitInfo.WaveLength + (int)utt.Segments[unitIndex + 1].WaveUnitInfo.WaveLength; int segStart = (int)utt.Segments[unitIndex].WaveUnitInfo.RecordingWaveStartPosition; int segEnd = segStart + (int)utt.Segments[unitIndex].WaveUnitInfo.WaveLength; scriptPhone.Acoustics.SegmentIntervals.Add(new SegmentInterval(segStart, segEnd)); segStart = (int)utt.Segments[unitIndex + 1].WaveUnitInfo.RecordingWaveStartPosition; segEnd = segStart + (int)utt.Segments[unitIndex + 1].WaveUnitInfo.WaveLength; scriptPhone.Acoustics.SegmentIntervals.Add(new SegmentInterval(segStart, segEnd)); } // Relative begin position of the uvsegment interval. int relativeBegin = 0; // Relative end position of the uvsegment interval. int relativeEnd = 0; // When go through the F0 values, this valuie to identify if meet the first voiced segment. bool reBeginPositionFindOut = false; // Check if all the F0 values in one state are equals to 0. If yes, don't write down the uvseg. bool isF0ValueExist = false; // Dump the durations and F0s in each state. if (utt.Acoustic.Durations != null) { for (int i = 0; i < utt.Acoustic.Durations[phoneIndex].Length; ++i) { ScriptState scriptState = new ScriptState(); // Dump duration int durationInFrame = (int)utt.Acoustic.Durations[phoneIndex][i]; scriptState.Acoustics = new ScriptAcoustics(durationInFrame * MillisecondsPerFrame); // Dump F0s if (utt.Acoustic.F0s != null) { ScriptUvSeg scriptUvSeg = GetF0Contour(utt, f0StartIndex, durationInFrame, ScriptAcousticChunkEncoding.Text, ref relativeBegin, ref relativeEnd, ref reBeginPositionFindOut, ref isF0ValueExist); if (isF0ValueExist == true) { scriptState.Acoustics.UvSegs.Add(scriptUvSeg); } f0StartIndex += durationInFrame; } scriptPhone.States.Add(scriptState); } } // Dump the uvsegment relative interval. if (utt.Acoustic.F0s != null && !phone.Pronunciation.Equals(PronOfSilence) && !phone.Pronunciation.Equals(PronOfShortPause)) { ScriptUvSeg uvSegForRelativeInterval = new ScriptUvSeg(ScriptUvSegType.Mixed); uvSegForRelativeInterval.Interval = new ScriptUvSegInterval(relativeBegin * 5, relativeEnd * 5); scriptPhone.Acoustics.UvSegs.Add(uvSegForRelativeInterval); } phoneIndex++; unitIndex++; if (wuiManager != null && !phone.Pronunciation.Equals(PronOfSilence) && !phone.Pronunciation.Equals(PronOfShortPause)) { // if it is not an silence phone, the according unit must be an half phone unit, // we need skip the right half phone to move next phone's unit unitIndex++; } scriptSyllable.Phones.Add(scriptPhone); if (phone == syllable.LastPhone) { break; } phone = phone.Next; } }
/// <summary> /// Load state from XmlTextReader. /// </summary> /// <param name="reader">Xml text reader.</param> /// <returns>Script state.</returns> private static ScriptState LoadState(XmlTextReader reader) { Debug.Assert(reader != null); ScriptState state = new ScriptState(); if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "acoustics") { state.Acoustics = new ScriptAcoustics(); state.Acoustics.ParseFromXml(reader); } else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "state") { break; } } } return state; }