Beispiel #1
0
        /// <summary>
        /// The speaking thread body.
        /// </summary>
        /// <remarks>This loops on the queue of things to say, and speaks them
        /// one at a time.</remarks>
        private void SpeakLoop()
        {
            QueuedSpeech utterance;

            try
            {
                while (running)
                {
                    // Wait for something to show up in the queue.
                    lock (queue)
                    {
                        while (queue.Count == 0)
                        {
                            Monitor.Wait(queue);
                        }

                        utterance = queue.Dequeue();
                    }

                    // Watch for the special "shutdown" message.
                    if (utterance.message == null &&
                        utterance.speaker == null)
                    {
                        running = false;
                        continue;
                    }

                    string thisfile = AUDIOFILE + string.Format("{0}", seq++) + ".wav";
                    if (seq > 4)
                    {
                        seq = 0;
                    }

                    // Synthesize it into a file.
                    syn.Speak(utterance, thisfile);

                    // TODO Get FMOD working on Mac
                    if (System.Environment.OSVersion.Platform != PlatformID.MacOSX)
                    {
                        // Play back the file
                        control.sound.Play(
                            thisfile,              // Name of the file
                            16000,                 // Same rate
                            utterance.position,    // Location
                            true,                  // Delete the file when done
                            utterance.isSpatial);  // Whether it is inworld or moves with listener
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Synth shutdown " + e.Message);
            }
        }