示例#1
0
        private static SentenceEvaluationResult CreateSentenceEvaluationResult(string[] phonemeEvaluationResults)
        {
            var validPhonemeEvaluationResults = phonemeEvaluationResults.Select(l => new PhonemeEvaluationResult(l)).Where(p => p.IsValid).GetEnumerator();
            var wordPhonemeEvaluationResults  = new List <PhonemeEvaluationResult>();
            var sentenceEvaluationResult      = new SentenceEvaluationResult
            {
                Words = new List <WordEvaluationResult>(),
            };

            while (true)
            {
                var eof = !validPhonemeEvaluationResults.MoveNext();

                if ((eof || validPhonemeEvaluationResults.Current.IsStartOfWord) && wordPhonemeEvaluationResults.Count != 0)
                {
                    var phonemesAvgScore = wordPhonemeEvaluationResults.Average(n => n.Score);
                    sentenceEvaluationResult.Words.Add(
                        new WordEvaluationResult
                    {
                        Score = Math.Round(ScoringHost.GetScorePercentage(phonemesAvgScore)),
                        //Score=phonemesAvgScore,
                        StartTime = wordPhonemeEvaluationResults.First().StartTime,
                        EndTime   = wordPhonemeEvaluationResults.Last().EndTime,
                        Word      = wordPhonemeEvaluationResults.First().Word,
                    });

                    wordPhonemeEvaluationResults.Clear();
                }

                if (eof)
                {
                    break;
                }

                wordPhonemeEvaluationResults.Add(validPhonemeEvaluationResults.Current);
            }

            var wordsAvgScore = sentenceEvaluationResult.Words.Average(w => w.Score);

            sentenceEvaluationResult.Score = Math.Round(wordsAvgScore);
            // sentenceEvaluationResult.Score = Math.Round( GetScorePercentage(wordsAvgScore));
            return(sentenceEvaluationResult);
        }
示例#2
0
        private static SentenceEvaluationResult CreateSentenceEvaluationResult(int wordsCount, string[] phonemeNativeResults, double[] f0Data, SupportedLanguage language)
        {
            if (phonemeNativeResults == null || phonemeNativeResults.Length <= 0)
            {
                throw new ArgumentException("Phoneme evaluation result is null or empty.");
            }

            var validPhonemeNativeResults = phonemeNativeResults.Select(l => new PhonemeNativeResult(l)).Where(p => p.IsValid);
            var startWordsCount           = validPhonemeNativeResults.Count(n => n.IsStartOfWord);

            if (startWordsCount != wordsCount)
            {
                throw new ArgumentException("Word count of phoneme evaluation result is not equal to original sentence.");
            }

            if (!validPhonemeNativeResults.First().IsStartOfWord)
            {
                throw new ArgumentException("The first phoneme is not start of a word.");
            }

            var enumerator = validPhonemeNativeResults.GetEnumerator();
            List <PhonemeEvaluationResult> wordPhonemeEvaluationResults = null;
            var sentenceEvaluationResult = new SentenceEvaluationResult
            {
                Words = new List <WordEvaluationResult>(),
            };

            var currentWord = string.Empty;

            while (true)
            {
                var eof = !enumerator.MoveNext();

                if ((eof || enumerator.Current.IsStartOfWord) &&
                    (wordPhonemeEvaluationResults != null && wordPhonemeEvaluationResults.Count != 0))
                {
                    var phonemesAvgScore = wordPhonemeEvaluationResults.Average(n => n.Score);
                    sentenceEvaluationResult.Words.Add(
                        new WordEvaluationResult
                    {
                        Score     = Math.Round(ScoringHost.GetScorePercentage(phonemesAvgScore), 2),
                        StartTime = wordPhonemeEvaluationResults.First().StartTime,
                        EndTime   = wordPhonemeEvaluationResults.Last().EndTime,
                        Word      = currentWord,
                        Phonemes  = wordPhonemeEvaluationResults,
                    });
                }

                if (eof)
                {
                    break;
                }

                if (enumerator.Current.IsStartOfWord)
                {
                    currentWord = enumerator.Current.Word;
                    wordPhonemeEvaluationResults = new List <PhonemeEvaluationResult>();
                }

                var phonemeEvaluationResult = new PhonemeEvaluationResult(enumerator.Current);

                if (language == SupportedLanguage.English)
                {
                    phonemeEvaluationResult.Phoneme = PhonemeConverter.ConvertToIPA(phonemeEvaluationResult.Phoneme, currentWord, wordPhonemeEvaluationResults.Count());
                }

                wordPhonemeEvaluationResults.Add(phonemeEvaluationResult);
            }

            var wordsAvgScore = sentenceEvaluationResult.Words.Average(w => w.Score);

            sentenceEvaluationResult.Score      = Math.Round(wordsAvgScore, 2);
            sentenceEvaluationResult.ToneF0Data = f0Data;

            return(sentenceEvaluationResult);
        }