| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Speech.text;
- using System.Diagnostics;
- namespace Speech {
- public static class SpeechExecute {
- public static SpeechCache Cache = new SpeechCache();
- public static tts.ISpeechSystem SpeechSystem;
- public static play.IPlaySystem PlaySystem;
- public static bool isGenerating = false;
- public static bool isPlaying = false;
- private static SpeechCacheEntry entry;
- public static string voice;
- public static int freq;
- public static string device;
-
- public static void Init() {
- Cache.Load("cache/speech.cah");
- }
- public static void Say(string s, bool bRaw = false) {
- Say(s, eMood.None, false);
- }
- public static bool Say(string s, eMood Mood , bool bRaw = false) {
- string formated = SpeechFormat.Format(s);
- string pronounced = formated;
- System.Diagnostics.Debug.WriteLine("Say('"+s+"', "+Mood+")");
- if (isPlaying || isGenerating) {
- System.Diagnostics.Debug.WriteLine("- Failed");
- if (isGenerating) System.Diagnostics.Debug.WriteLine(" - Already generating");
- if (isPlaying) System.Diagnostics.Debug.WriteLine(" - Is already playing");
- return false;
- }
- SpeechExecute.isGenerating = true;
- SpeechExecute.isPlaying = true;
- entry = Cache.find(formated);
- if (entry == null) {
- if (!bRaw) {
- pronounced = SpeechFormat.Pronounce(pronounced);
- }
- System.Diagnostics.Debug.WriteLine("Generate TTS");
- entry = Cache.Add(formated, Mood);
- entry.LastAccess = DateTime.Now;
- System.Diagnostics.Debug.WriteLine("- Cache FileName: " + entry.File);
- Process p = SpeechSystem.GenerateTTS(entry.File, voice, "de-DE", pronounced);
- Console.WriteLine("Generate TTS: '" + pronounced + "'");
- //p.Exited += Generate_Exited;
- p.Start();
- p.WaitForExit();
- } else {
- System.Diagnostics.Debug.WriteLine("- Cache");
- entry.LastAccess = DateTime.Now;
- }
- SpeechExecute.isGenerating = false;
- Cache.Save("cache/speech.cah");
- Play();
- return true;
- }
- private static void Play() {
- Process p = PlaySystem.Play(entry.File, device, freq);
- p.Start();
- p.WaitForExit();
- SpeechExecute.isPlaying = false;
- }
- }
- }
|