用Agent+ASP技术制作语音聊天室

用Agent+ASP技术制作语音聊天室
--------------------以下为程序内容,按文章中出现的顺序分块排序

1<object classid="clsid:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F" codebase="#VERSION=2,0,0,0" id="Agent">
2</object>
1<object classid="clsid:B8F2846E-CE36-11D0-AC83-00C04FD97575" codebase="#VERSION=6,0,0,0" height="14" id="TruVoice" width="14">
2</object>

尝试从微软Agent角色目录中装载
Set LoadRequestUNC = Agent.Characters.Load ("Peedy", "Peedy.acs")

If LoadRequestUNC.Status <> 0 Then
' 如果失败便尝试从微软服务器下载
Set LoadRequestURL = Agent.Characters.Load ("Peedy", "http://agent.microsoft.com/agent2/chars/peedy/peedy.acf")
Else
' 现在产生一个Peedy实例
Set Peedy = Agent.Characters("Peedy")
End If


 1<html>
 2<body>
 3<h3 align="center"><font color="#0000FF">Welcome to My Chatroom!</font></h3>
 4<form action="default.asp" method="POST">
 5<p align="center">Your name please:   
 6<input name="txtUsername" size="20" type="text"/>
 7<input name="btnOK" type="submit" value="OK"/></p>
 8</form>
 9<p align="center"><a href="download.htm">Click here to go to download page.</a></p>
10</body>
11</html>

1<script language="VBScript" runat="Server">   
2Sub Application_OnStart   
3Application("message")="" '发言内容   
4Application("expression")="" '表情   
5Application("sender")="" '发言者ID   
6Application("globalid")=0 '发言总序号   
7End Sub   
8</script>

1   
2Session("username") = Server.HtmlEncode(Request.Form("txtUsername"))   
3Session("personalid")=0   
 1<html>
 2<head>
 3<title>Welcome to My Chatroom!</title>
 4</head>
 5<frameset border="0" cols="98,*" frameborder="0" framespacing="0">
 6<frame name="agent" src="agent.asp"/>
 7<frameset rows="196,68,*">
 8<frame name="display" src="display.asp"/>
 9<frame name="refresh" src="refresh.asp"/>
10<frame name="message" src="message.asp"/>
11</frameset>
12</frameset>
13<frameset>
14</frameset>
15</html>

 1<html>
 2<body bgcolor="#006699" text="#FFFFFF">
 3<!--定义"AgentControl"-->
 4<object classid="clsid:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F" codebase="#VERSION=2,0,0,0" id="Agent">
 5</object>
 6<!--定义L&H TruVoice Text-To-Speech American English -->
 7<object classid="clsid:B8F2846E-CE36-11D0-AC83-00C04FD97575" codebase="#VERSION=6,0,0,0" height="14" id="TruVoice" width="14">
 8</object>
 9<script language="VBScript">   
10Dim Peedy   
11Dim LoadRequestUNC   
12Dim LoadRequestURL   
13Dim GetShowAnimation   
14  
15Sub Window_OnLoad   
16LoadCharacter   
17' 设置Agent的语言代号   
18Peedy.LanguageID = &H0409   
19' 让Peedy出现   
20Peedy.MoveTo window.event.screenX-100,window.event.screenY-100   
21Peedy.Show   
22' 好啦,Peedy可以开口说话了   
23Peedy.Speak "Welcome to my chatroom!"   
24Peedy.Play "Greet"   
25End Sub   
26  
27Sub Agent_RequestComplete(ByVal Request)   
28' 如果是从微软服务器装载ACF角色的请求结束   
29If Request = LoadRequestURL Then   
30' 如果申请下载失败   
31If Request.Status = 1 Then   
32Msgbox "无法从服务器下载Peedy,可能服务器太忙。"   
33Exit Sub   
34' 如果成功   
35ElseIf Request.Status = 0 Then   
36' 产生一个实例   
37Set Peedy = Agent.Characters("Peedy")   
38' 预取Peedy的部分动画效果   
39Set GetShowAnimation = Peedy.Get ("state", "showing, speaking")   
40Peedy.Get "animation", "Blink, Greet, Pleased, Explain, Think, GestureRight,Idle1_1,Idle2_2, Announce, Uncertain", False   
41End If   
42' 如果是请求预取动画效果的请求结束   
43ElseIf Request = GetShowAnimation Then   
44' 如果失败   
45If Request.Status = 1 Then   
46Msgbox "下载动画的请求失败,可能服务器太忙。"   
47Exit Sub   
48End If   
49End If   
50End Sub   
51  
52' 装载Agent角色   
53Sub LoadCharacter   
54On Error Resume Next   
55' 尝试从微软Agent角色目录中装载   
56Set LoadRequestUNC = Agent.Characters.Load ("Peedy", "Peedy.acs")   
57  
58If LoadRequestUNC.Status <> 0 Then   
59' 如果失败便尝试从微软服务器下载   
60Set LoadRequestURL = Agent.Characters.Load ("Peedy", "http://agent.microsoft.com/agent2/chars/peedy/peedy.acf")   
61Else   
62' 产生一个Peedy实例   
63Set Peedy = Agent.Characters("Peedy")   
64End If   
65End Sub   
66  
67</script>
68</body>
69</html>

1<html>
2<head>
3<meta content="3" http-equiv="REFRESH" url="refresh.asp"/>
4</head>
5<body>
6<script language="VBScript">   
7Sub Window_OnLoad   

If Session("personalid") < Application("globalid") Then

 1self.parent.display.document.write("<table width=100% border=0 cellPadding=0 cellSpacing=0><font color=#0000FF>"+"```
 2=Application("sender")
 3```"+"</font>: "+"```
 4=Application("message")
 5```"+"</table>")   
 6self.parent.display.scroll 0, 20000000   
 7self.parent.agent.Peedy.Speak "```
 8=Application("message")
 9```"   
10self.parent.agent.Peedy.Play "```
11=Application("expression")
12```"   

Session("personalid") = Application("globalid")
End If

1End Sub   
2</script>
3</body>
4</html>

1   
2Application.Lock   
3If Request.Form("txtMessage") <> "" Then   
4Application("message") = Server.HtmlEncode(Request.Form("txtMessage"))   
5Application("sender") = Session("username")   
6Application("expression") = Request.Form("rdoExpression")   
7Application("globalid") = Application("globalid") + 1   
8End If   
9Application.UnLock   
 1<html>
 2<head>
 3<style type="text/css">   
 4.smalltext {font-size: 9pt}   
 5</style></head>
 6<body bgcolor="#006699" onload="document.frmMessage.txtMessage.focus();" text="#FFFFFF">
 7<form action="message.asp" method="POST" name="frmMessage">
 8<p class="smalltext">   
 9You are welcome,```
10=Session("username")

 

Choose an expression:
Normal Explain Greet Congratulate Decline Pleased Think Announce Uncertain Gesture Right Don't Recognize Get Attention Do Magic

Message:

```
Published At
Categories with Web编程
Tagged with
comments powered by Disqus