Beispiel #1
0
        private static void Initialize(string modelFolder)
        {
            Trace.TraceInformation("ScoringHost::Initialize(), Path=" + modelFolder);
            try
            {
                NativeMethods.LoadModel(modelFolder); // alignment by likelihood
                var t = string.Format("HTKfunctions -C {0}", Path.Combine(modelFolder, "hcopy.config"));

                NativeMethods.InitializeMfcExtraction(string.Format("HTKfunctions -C {0}", Path.Combine(modelFolder, "hcopy.config")));
                NativeMethods.InitializeF0Extraction(
                    string.Format("F0Extraction -C {0}", Path.Combine(modelFolder, "getf0.config")));
                phonemeDictionary = new HashSet <string>(ParsePhonemeDictionay(Path.Combine(modelFolder, "evadict")));
                PhonemeConverter.Initialize(Path.Combine(modelFolder, "cmudict"));
            }
            catch (Exception e)
            {
                Trace.TraceError(
                    "ScoringHost::Initialize(), unexpected exception, Message={0}, Stack={1}",
                    e.Message,
                    e.StackTrace);

                throw;
            }
        }
Beispiel #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);
        }