aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/mass test client/Commands/Communication/TtsCommand.cs
blob: 52b7a39a5497cadd7f4372a5d6ba20e50a729421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Text;
using System.Speech.Synthesis;
using libsecondlife;
using libsecondlife.Packets;
using libsecondlife.AssetSystem;


// Since this requires .Net 3.0 I've left it out of the project by default.
// To use this: include it in the project and add a reference to the System.Speech.dll

namespace libsecondlife.TestClient
{
    public class TtsCommand : Command
    {
		SpeechSynthesizer _speechSynthesizer;

		public TtsCommand(TestClient testClient)
        {
            Name = "tts";
            Description = "Text To Speech.  When activated, client will echo all recieved chat messages out thru the computer's speakers.";
        }

        public override string Execute(string[] args, LLUUID fromAgentID)
        {
			if (!Active)
			{
				if (_speechSynthesizer == null)
					_speechSynthesizer = new SpeechSynthesizer();
				Active = true;
				Client.Self.OnChat += new MainAvatar.ChatCallback(Self_OnChat);
				return "TTS is now on.";
			}
			else
			{
				Active = false;
				Client.Self.OnChat -= new MainAvatar.ChatCallback(Self_OnChat);
				return "TTS is now off.";
			}
        }

		void Self_OnChat(string message, byte audible, byte type, byte sourcetype, string fromName, LLUUID id, LLUUID ownerid, LLVector3 position)
		{
			if (message.Length > 0)
			{
				_speechSynthesizer.SpeakAsync(message);
			}
		}
	}
}