コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlScriptValidateSetting"/> class.
        /// </summary>
        /// <param name="phoneSet">Phone set.</param>
        /// <param name="posSet">POS set.</param>
        public XmlScriptValidateSetting(TtsPhoneSet phoneSet, TtsPosSet posSet) 
        {
            _scope = XmlScriptValidationScope.None;

            if (phoneSet != null)
            {
                _scope |= XmlScriptValidationScope.Pronunciation;
            }

            if (posSet != null)
            {
                _scope |= XmlScriptValidationScope.POS;
            }

            _phoneSet = phoneSet;
            _posSet = posSet;
        }
コード例 #2
0
        /// <summary>
        /// Check whether the element is valid or not.
        /// </summary>
        /// <param name="itemID">ID of the script item.</param>
        /// <param name="nodePath">Path of the node.</param>
        /// <param name="scope">The validation setting.</param>
        /// <param name="errors">Contains errors found at present.</param>
        /// <returns>Valid or not. Always true if no validation is performed.</returns>
        public bool IsValid(string itemID, string nodePath, XmlScriptValidationScope scope, ErrorSet errors)
        {
            bool valid = true;

            if (HasAcousticsValue)
            {
                string path = string.Format(CultureInfo.InvariantCulture, "{0}.Acoustics", nodePath);
                if (!Acoustics.IsValid(itemID, path, scope, errors))
                {
                    valid = false;
                }
            }

            return valid;
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XmlScriptValidateSetting"/> class.
 /// </summary>
 public XmlScriptValidateSetting()
 {
     _scope = XmlScriptValidationScope.None;
 }
コード例 #4
0
        /// <summary>
        /// Check whether the element is valid or not.
        /// </summary>
        /// <param name="itemID">ID of the script item.</param>
        /// <param name="nodePath">Path of the node.</param>
        /// <param name="scope">The validation setting.</param>
        /// <param name="errors">Contains errors found at present.</param>
        /// <returns>Valid or not. Always true if no validation is performed.</returns>
        public bool IsValid(string itemID, string nodePath, XmlScriptValidationScope scope, ErrorSet errors)
        {
            bool valid = true;

            for (int i = 0; i < _syllables.Count; i++)
            {
                ScriptSyllable syllable = _syllables[i];
                string path = string.Format(CultureInfo.InvariantCulture, "{0}.Syllable[{1}]", nodePath, i);
                if (!syllable.IsValid(itemID, path, scope, errors))
                {
                    valid = false;
                }
            }

            if (HasAcousticsValue)
            {
                string path = string.Format(CultureInfo.InvariantCulture, "{0}.Acoustics", nodePath);
                if (!Acoustics.IsValid(itemID, path, scope, errors))
                {
                    valid = false;
                }
            }

            return valid;
        }
コード例 #5
0
        /// <summary>
        /// Check whether the element is valid or not.
        /// </summary>
        /// <param name="itemID">ID of the script item.</param>
        /// <param name="nodePath">Path of the node.</param>
        /// <param name="scope">The validation scope.</param>
        /// <param name="errors">Contains errors found at present.</param>
        /// <returns>Valid or not. Always true if no validation is performed.</returns>
        public bool IsValid(string itemID, string nodePath, XmlScriptValidationScope scope, ErrorSet errors)
        {
            bool valid = true;

            if ((scope & XmlScriptValidationScope.F0) == XmlScriptValidationScope.F0)
            {
                foreach (float f0 in _contour)
                {
                    if (f0 < 0)
                    {
                        errors.Add(ScriptError.F0Error, itemID, nodePath, f0.ToString(CultureInfo.InvariantCulture));
                        valid = false;
                        break;
                    }
                }
            }

            return valid;
        }
コード例 #6
0
        /// <summary>
        /// Check whether the element is valid or not.
        /// </summary>
        /// <param name="itemID">ID of the script item.</param>
        /// <param name="nodePath">Path of the node.</param>
        /// <param name="scope">The validation scope.</param>
        /// <param name="errors">Contains errors found at present.</param>
        /// <returns>Valid or not. Always true if no validation is performed.</returns>
        public bool IsValid(string itemID, string nodePath, XmlScriptValidationScope scope, ErrorSet errors)
        {
            bool valid = true;

            if ((scope & XmlScriptValidationScope.SegmentInterval) == XmlScriptValidationScope.SegmentInterval)
            {
                if (!InnerIsValid())
                {
                    errors.Add(ScriptError.SegmentIntervalError, itemID, nodePath,
                        Begin.ToString(CultureInfo.InvariantCulture), End.ToString(CultureInfo.InvariantCulture));
                    valid = false;
                }
            }

            return valid;
        }
コード例 #7
0
        /// <summary>
        /// Check whether the element is valid or not.
        /// </summary>
        /// <param name="itemID">ID of the script item.</param>
        /// <param name="nodePath">Path of the node.</param>
        /// <param name="scope">The validation scope.</param>
        /// <param name="errors">Contains errors found at present.</param>
        /// <returns>Valid or not. Always true if no validation is performed.</returns>
        public bool IsValid(string itemID, string nodePath, XmlScriptValidationScope scope, ErrorSet errors)
        {
            bool valid = true;

            foreach (ScriptUvSeg uvSeg in _scriptUvSegs)
            {
                if (!uvSeg.IsValid(itemID, nodePath, scope, errors))
                {
                    valid = false;
                }
            }

            if (HasSegmentInterval)
            {
                valid = _segmentIntervals.All(seg => seg.IsValid(itemID, nodePath, scope, errors));
            }

            int preBegin = 0;
            int preEnd = 0;
            foreach (ScriptUvSeg uvSeg in _scriptUvSegs)
            {
                if (uvSeg.HasIntervalValue)
                {
                    if ((scope & XmlScriptValidationScope.UvSegSequence) == XmlScriptValidationScope.UvSegSequence)
                    {
                        if (uvSeg.Interval.End <= preBegin)
                        {
                            errors.Add(ScriptError.UvSegOrderError, itemID, nodePath);
                            valid = false;
                            break;
                        }
                        else if (uvSeg.Interval.Begin < preEnd)
                        {
                            errors.Add(ScriptError.UvSegOverlappingError, itemID, nodePath);
                            valid = false;
                            break;
                        }
                        else
                        {
                            preBegin = uvSeg.Interval.Begin;
                            preEnd = uvSeg.Interval.End;
                        }
                    }

                    if (((scope & XmlScriptValidationScope.DurationAndInterval) == XmlScriptValidationScope.DurationAndInterval)
                        && HasDurationValue)
                    {
                        if (uvSeg.Interval.End > _duration)
                        {
                            errors.Add(ScriptError.DurationAndIntervalError, itemID, nodePath);
                            valid = false;
                            break;
                        }
                    }

                    if (((scope & XmlScriptValidationScope.SegmentDurationAndInterval) == XmlScriptValidationScope.SegmentDurationAndInterval)
                        && HasSegmentInterval)
                    {
                        if (uvSeg.Interval.End > SegmentIntervals.Sum(seg => seg.IntervalDuration))
                        {
                            errors.Add(ScriptError.SegmentDurationAndIntervalError, itemID, nodePath);
                            valid = false;
                            break;
                        }
                    }
                }
            }

            if (((scope & XmlScriptValidationScope.DurationAndSegment) == XmlScriptValidationScope.DurationAndSegment)
                && HasDurationValue && HasSegmentInterval && _duration != SegmentIntervals.Sum(seg => seg.IntervalDuration))
            {
                errors.Add(ScriptError.DurationAndSegmentError, itemID, nodePath,
                    _duration.ToString(CultureInfo.InvariantCulture),
                    SegmentIntervals.First().Begin.ToString(CultureInfo.InvariantCulture),
                    SegmentIntervals.Last().End.ToString(CultureInfo.InvariantCulture));
                valid = false;
            }

            return valid;
        }
コード例 #8
0
        /// <summary>
        /// Check whether the element is valid or not.
        /// </summary>
        /// <param name="itemID">ID of the script item.</param>
        /// <param name="nodePath">Path of the node.</param>
        /// <param name="scope">The validation scope.</param>
        /// <param name="errors">Contains errors found at present.</param>
        /// <returns>Valid or not. Always true if no validation is performed.</returns>
        public bool IsValid(string itemID, string nodePath, XmlScriptValidationScope scope, ErrorSet errors)
        {
            bool valid = true;
            if (HasIntervalValue)
            {
                if (!_interval.IsValid(itemID, nodePath, scope, errors))
                {
                    valid = false;
                }
            }

            if (HasF0ContourValue)
            {
                if (!_f0Contour.IsValid(itemID, nodePath, scope, errors))
                {
                    valid = false;
                }
            }

            if ((scope & XmlScriptValidationScope.F0AndUvType) == XmlScriptValidationScope.F0AndUvType)
            {
                switch (_segType)
                {
                    case ScriptUvSegType.Unknown:
                        string message = string.Format(CultureInfo.InvariantCulture,
                            "Invalid unvoiced-voiced segment type ScriptUvSegType.Unknown.");
                        throw new InvalidDataException(message);

                    case ScriptUvSegType.Voiced:
                        if (HasF0ContourValue)
                        {
                            foreach (float f0 in _f0Contour.Contour)
                            {
                                if (f0 >= 0 && f0 <= MinF0Value)
                                {
                                    errors.Add(ScriptError.F0AndUvTypeError, itemID, nodePath);
                                    valid = false;
                                    break;
                                }
                            }
                        }

                        break;

                    case ScriptUvSegType.Unvoiced:
                        if (HasF0ContourValue)
                        {
                            foreach (float f0 in _f0Contour.Contour)
                            {
                                if (f0 > MinF0Value)
                                {
                                    errors.Add(ScriptError.F0AndUvTypeError, itemID, nodePath);
                                    valid = false;
                                    break;
                                }
                            }
                        }

                        break;

                    case ScriptUvSegType.Silence:
                        if (HasF0ContourValue)
                        {
                            foreach (float f0 in _f0Contour.Contour)
                            {
                                if (f0 > MinF0Value)
                                {
                                    errors.Add(ScriptError.F0AndUvTypeError, itemID, nodePath);
                                    valid = false;
                                    break;
                                }
                            }
                        }

                        break;

                    case ScriptUvSegType.Mixed:
                        break;
                }
            }

            return valid;
        }