Ejemplo n.º 1
0
 /// <summary>
 /// Enqueues provided SpeechTextTask to perform a TTS asinchronously
 /// </summary>
 /// <param name="textToSay">SpeechTextTask cotaining the text to speech out</param>
 /// <returns>true if provided text was enqueued, false otherwise</returns>
 public override bool SpeakAsync(SpeechTextTask task)
 {
     if (speechSynth == null)
     {
         return(false);
     }
     return(base.SpeakAsync(task));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Enqueues provided SpeechTextTask to perform a TTS asinchronously
 /// </summary>
 /// <param name="textToSay">SpeechTextTask cotaining the text to speech out</param>
 /// <returns>true if provided text was enqueued, false otherwise</returns>
 public virtual bool SpeakAsync(SpeechTextTask task)
 {
     if (task == null)
     {
         return(false);
     }
     //if (speechQueue.Count >= speechQueue.Capacity)
     //	return false;
     speechQueue.Produce(task);
     return(true);
 }
Ejemplo n.º 3
0
        protected virtual void SpeechThreadTask()
        {
            running = true;
            #region Voices Initialization
            // Voices Initialization
            //while (running && (voiceNames.Count < 1))
            //{
            //    Thread.Sleep(100);
            //    LoadVoices();
            //}
            #endregion

            while (running)
            {
                try
                {
                    SpeechTextTask stt = speechQueue.Consume(100);
                    if (stt == null)
                    {
                        continue;
                    }
                    Speak(stt);
                }
                catch (ThreadInterruptedException tiex)
                {
                    Console.WriteLine("SpeechThread aborted: " + tiex.ToString());
                    return;
                }
                catch (ThreadAbortException taex)
                {
                    Console.WriteLine("SpeechThread aborted: " + taex.ToString());
                    ShutUp();
                    return;
                }
                catch { continue; }
            }
            ShutUp();
            speechQueue.Clear();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the read command
        /// </summary>
        /// <param name="command">Command object which contains the command to be executed</param>
        /// <returns>The Response object result of provided command execution. If no response is required, must return null</returns>
        /// <remarks>If the command execution is aborted the execution of this method is
        /// canceled and a failure response is sent if required</remarks>
        protected override Response AsyncTask(Command command)
        {
            bool           result;
            string         textToSay;
            SpeechTextTask task;

            result = false;
            try
            {
                if (File.Exists(command.Parameters))
                {
                    textToSay = System.IO.File.ReadAllText(command.Parameters);
                    //if (spGen.IsSpeaking || (spGen.Pending > 0))
                    //    result = false;
                    //else
                    //    result = spGen.SpeakSync(textToSay);

                    task = new SpeechTextTask(textToSay);
                    if (!spGen.SpeakAsync(task))
                    {
                        return(Response.CreateFromCommand(command, false));
                    }
                    while ((task.Status == SpeechTextTaskStatus.Pending) || (task.Status == SpeechTextTaskStatus.Speaking))
                    {
                        System.Threading.Thread.Sleep(1);
                    }
                    result = task.Status == SpeechTextTaskStatus.CompletedSuccessfully;
                }
            }
            catch
            {
                result = false;
            }

            return(Response.CreateFromCommand(command, result));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes a TTS sinchronously
        /// </summary>
        /// <param name="textToSay">text to speech out</param>
        /// <returns>true if provided text was spoken, false otherwise</returns>
        protected override bool Speak(SpeechTextTask speechTask)
        {
            bool locked;

            if (speechSynth == null)
            {
                return(false);
            }
            if (speechTask == null)
            {
                return(false);
            }

            string original = speechTask.TTS;
            string tts      = speechTask.TTS;

            //if (selectedVoiceName == "Susan")
            //{
            //    tts = tts.Replace("robot", "row-bought");
            //    tts = tts.Replace("_", " ");
            //    tts = tts.Replace("stop", "stup");
            //}
            for (int i = 0; i < this.pronunciation.Count; ++i)
            {
                tts = this.pronunciation[i].ReplaceWordByPronunciation(tts);
            }

            if ((speechSynth.State != SynthesizerState.Ready) || !Monitor.TryEnter(speechSynth))
            {
                return(false);
            }
            locked            = true;
            Speaking          = true;
            SpokenString      = original;
            speechTask.Status = SpeechTextTaskStatus.Speaking;
            lastSpeechResult  = SpeakOperationResult.Error;

            try
            {
                OnSpeakStarted(tts);
                if (speechSynth.Voice.Name != selectedVoiceName)
                {
                    speechSynth.SelectVoice(selectedVoiceName);
                }
                speechSynth.SpeakAsync(tts);
                Monitor.Wait(speechSynth);
                Monitor.Exit(speechSynth);
                locked = false;
            }
            catch
            {
                if (locked)
                {
                    Monitor.Exit(speechSynth);
                }
                Speaking          = ((speechSynth.State == SynthesizerState.Speaking) || (speechQueue.Count != 0));
                speechTask.Status = SpeechTextTaskStatus.CompleteFailed;
                return(false);
            }
            speechTask.Status = (lastSpeechResult == SpeakOperationResult.Succeeded) ? SpeechTextTaskStatus.CompletedSuccessfully : SpeechTextTaskStatus.CompleteFailed;
            return(lastSpeechResult == SpeakOperationResult.Succeeded);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Executes a TTS sinchronously
 /// </summary>
 /// <param name="textToSay">text to speech out</param>
 /// <returns>true if provided text was spoken, false otherwise</returns>
 protected abstract bool Speak(SpeechTextTask speechTask);