コード例 #1
0
 public void stop()
 {
     audioProcessor.stop();
     audioProcessor = new LogPlayer();
 }
コード例 #2
0
        public void generateSynthesisData(Story story)
        {
            saveData = true;
            foreach (InstalledVoice iv in synthesizer.GetInstalledVoices())
            {
                string voiceName = iv.VoiceInfo.Name;
                Debug.WriteLine("installed voice :" + voiceName);
                synthesizer.SelectVoice(voiceName);
                string path = story.getFullPath() + "\\" + EBookInteractiveSystem.voice_dir + "\\" + voiceName.Replace(" ", "_");
                Directory.CreateDirectory(path);
                int  index = 0;
                Page p     = story.GetFirstPage();

                logResultFile = path + "\\" + StoryLoggingDevice.logFileName;

                if (File.Exists(logResultFile))
                {
                    Debug.WriteLine("skip gnerating synthesis data, data found in " + path);
                    return;
                }
                startTime = (long)LogPlayer.GetUnixTimestamp();

                while (p != null)
                {
                    //reset startIndex when start a new page
                    startIndex = 0;

                    List <string[]> textArray = p.GetListOfTextArray();
                    string          whole     = "";
                    foreach (string[] text in textArray)
                    {
                        if (text != null)
                        {
                            foreach (string ea in text)
                            {
                                whole += ea + " ";
                            }
                        }
                    }
                    string[]      separator = { "!", "?", "." };
                    string[]      sp        = whole.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                    List <string> sentences = new List <string>();
                    string        tmpStr    = "";
                    foreach (string ea in sp)
                    {
                        tmpStr += ea + " ";
                        foreach (string punc in separator)
                        {
                            if (ea.Contains(punc))
                            {
                                sentences.Add(tmpStr.TrimEnd());
                                tmpStr = "";
                                break;
                            }
                        }
                    }
                    foreach (string ea in sentences)
                    {
                        Debug.WriteLine("generating tts for:" + ea);
                        string audioPath = path + "\\" + getPrefix(index) + ".wav";
                        synthesizer.SetOutputToWaveFile(@audioPath);

                        PromptBuilder pb = new PromptBuilder();
                        synthesizer.Rate = synthesisSpeakRate;
                        prompt           = "";
                        writeToFile("start::" + startTime + "\n");
                        startTime += 10;
                        synthesizer.Speak(ea);
                        index++;
                        startTime += (totalSentenceDuration);

                        string data = "time::" + startTime + "|confidence::0.99|textResult::" + prompt.Trim() +
                                      "|isHypothesis::False|key::startIndex|value::" + startIndex + "|grammarName::|ruleName::index_" +
                                      startIndex + "|duration::" + totalSentenceDuration + "|wavePath::" + EBookUtil.convertAudioToRelativePath(@audioPath) + "\n";
                        writeToFile(data);

                        string[] tmp = ea.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
                        startIndex += tmp.Length;

                        startTime += 1000;//one second pause
                    }
                    writeToFile("finishPage\n");
                    p = story.GetNextPage();
                }
            }
            saveData = false;
        }
コード例 #3
0
 public StoryManager()
 {
     textProcessor  = new TextProcessor();
     audioProcessor = new LogPlayer();
     storyLogger    = new StoryLoggingDevice();
 }