CSDN博客

img greystar

网页中调用MS代理

发表于2004/9/21 16:42:00  1144人阅读

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>无标题 签名</TITLE>
<OBJECT id=AgentControl codeBase=#VERSION=2,0,0,0 height=0 width=0
classid=CLSID:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F></OBJECT>
<OBJECT id=L&amp;HTruVoice codeBase=#VERSION=6,0,0,0 height=0 width=0
classid=CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575></OBJECT>
<SCRIPT language=JavaScript>
<!--//
// * Character Objects
var Merlin;

// * Variables
var UsedChars;
var MerlinID;
var MerlinACS;
var MerlinURL;
var MerlinStates;
var MerlinAnimations;
var MerlinReq;
var MerlinStatesReq;
var MerlinAnimationsReq;
var MerlinLoaded;
var LoadReq;
var HideReq;
var MerlinLeftX, MerlinCenterX, MerlinRightX;
var MerlinTopY, MerlinCenterY, MerlinBottomY;

// * Initialize
UsedChars = "Merlin";

// * Merlin
MerlinID = "Merlin";
MerlinACS = "merlin.acs";
//MerlinURL = "http://agent.microsoft.com/agent2/chars/merlin/merlin.acf";
MerlinURL="#"
MerlinStates = "Showing, Hiding, Speaking, Moving, Gesturing, Idling, Hearing, Listening";
MerlinAnimations = "GestureLeft, Surprised";
MerlinLoaded = false;


Window_OnLoad();

function Window_OnLoad() {
   
//目的:在页面打开时自动运行程序 
    // * INSERT ANY NON-AGENT RELATED SCRIPTING HERE

    AgentControl.Connected = true;

    MerlinLoaded = LoadLocalAgent(MerlinID, MerlinACS);

    if (MerlinLoaded) {
        SetCharObj();
    }
    CheckLoadStatus();
}

function LoadLocalAgent(CharID, CharACS) {
    // Purpose:  Attempts to load the specified character
    // Returns:  true if successful, false if not

    AgentControl.RaiseRequestErrors = false;
    LoadReq = AgentControl.Characters.Load(CharID, CharACS);
    AgentControl.RaiseRequestErrors = true;

    if (LoadReq.Status != 1) {
        return(true);
    }
    return(false);
}

function SetCharObj() {
    // Purpose:  Sets the character reference and TTS Language ID

    Merlin = AgentControl.Characters.Character(MerlinID);
    Merlin.LanguageID = 0x409 ;
}

function CheckLoadStatus() {
    // Purpose:  Determines if required characters have been loaded.
    //           If not, issue request to load next character
    //           else run the AgentIntro routine

    if (!MerlinLoaded) {
        window.status = "Loading " + MerlinID + " Character.  Please Wait...";
        MerlinReq = AgentControl.Characters.Load(MerlinID, MerlinURL);
        return(false);
    }

    window.status = "";
    AgentIntro();
    return(true);
}

function LoadError() {
    var strMsg;
    window.status = "";
    strMsg = "Error Loading Character: " + MerlinID + "/n";
    strMsg = strMsg + "This Microsoft Agent Script requires the character(s):/n";
    strMsg = strMsg + UsedChars;
    alert(strMsg);
}
function GetScreenPositions() {
    var ScreenWidth = window.screen.width;
    var ScreenHeight = window.screen.height;

    if ((ScreenWidth == 0) || (ScreenHeight == 0)) {
        ScreenWidth = 800;
        ScreenHeight = 600;
    }

    MerlinCenterX = (parseInt(ScreenWidth / 2) - parseInt(Merlin.Width / 2));
    MerlinRightX = (ScreenWidth - Merlin.Width);
    MerlinCenterY = (parseInt(ScreenHeight / 2) - parseInt(Merlin.Height / 2));
    MerlinBottomY = (ScreenHeight - Merlin.Height);
}

function InitAgentCommands() {
    // Purpose:  Initialize the Commands menu

    Merlin.Commands.RemoveAll();
    Merlin.Commands.Caption = "My Menu Name";
    Merlin.Commands.Add("ACO", "Advanced Character Options", "Advanced Character Options");
}

function AgentIntro() {
    GetScreenPositions();
    InitAgentCommands();


    Merlin.MoveTo(MerlinLeftX, MerlinTopY);
    Merlin.Show();
    Merlin.Speak("Hello I'am greystar!");
    Merlin.Think("What do you want to know?");
    Merlin.Play("GestureLeft");
    Merlin.Speak("Help yourself to read!");
    Merlin.Play("Surprised");
  
    Merlin.Hide();

}
//-->
  </SCRIPT>

<SCRIPT language=JavaScript event=RequestComplete(RequestObject)
for=AgentControl>
<!--//
    // Purpose:  Take action on completion or failure of requests

{
    switch (RequestObject) {
    case MerlinReq :
        if (RequestObject.Status == 0) {
            SetCharObj();

            if (MerlinStates != "") {
                window.status = "Loading " + MerlinID + " States.  Please Wait...";
                MerlinStatesReq = AgentControl.Characters(MerlinID).Get("State", MerlinStates, true);
            }
            else if (MerlinAnimations != "") {
                window.status = "Loading " + MerlinID + " Animations.  Please Wait...";
                MerlinAnimationsReq = AgentControl.Characters(MerlinID).Get("Animation", MerlinAnimations, true);
            }
            else {
                MerlinLoaded = true;
                CheckLoadStatus();
            }
        }
        else {
            LoadError();
        }
        break;
    case MerlinStatesReq :
        if (RequestObject.Status == 0) {
            if (MerlinAnimations != "") {
                window.status = "Loading " + MerlinID + " Animations.  Please Wait...";
                MerlinAnimationsReq = AgentControl.Characters(MerlinID).Get("Animation", MerlinAnimations, true);
            }
            else {
                MerlinLoaded = true;
                CheckLoadStatus();
            }
        }
        else
        {
            LoadError();
        }
        break;
    case MerlinAnimationsReq :
        if (RequestObject.Status == 0)
        {
            MerlinLoaded = true;
            CheckLoadStatus();
        }
        else
        {
            LoadError();
        }
        break;
    case HideReq :
        AgentControl.Characters.Unload(MerlinID);
        break;
    } // end switch
}
//-->
  </SCRIPT>

<SCRIPT language=JavaScript event=Command(UserInput) for=AgentControl>
<!--//
    // Purpose:  Determine Command that was selected either by menu or voice
    //           and run the applicable Command Script
    var BadConfidence;
    BadConfidence = 10;

    if (UserInput.Confidence <= -40)
    {
        // Bad Recognition
    }
    else if ((UserInput.Alt1Name != "") && (Math.abs(Math.abs(UserInput.Alt1Confidence) - Math.abs(UserInput.Confidence)) < BadConfidence))
    {
        // Bad Confidence - too close to another command
    }
    else if ((UserInput.Alt2Name != "") && (Math.abs(Math.abs(UserInput.Alt1Confidence) - Math.abs(UserInput.Confidence)) < BadConfidence))
    {
        // Bad Confidence - too close to another command
    }
    else
    {
        // High Confidence
        switch(UserInput.Name) {
        case "ACO" :
            AgentControl.PropertySheet.Visible = true;
            break;
        }

    }
//-->
  </SCRIPT>

<SCRIPT language=JavaScript event=Bookmark(BookmarkID) for=AgentControl>
<!--//
//-->
  </SCRIPT>

<SCRIPT language=JavaScript event="Click(CharacterID, Button, Shift, X, Y)"
for=AgentControl>
<!--
    // Insert Click Event Code Here
-->
  </SCRIPT>

<SCRIPT language=JavaScript event="DblClick(CharacterID, Button, Shift, X, Y)"
for=AgentControl>
<!--
    // Purpose:  Stop and Hide all characters on double-click

    Merlin.StopAll();
    if (!Merlin.HasOtherClients)
    {
        if (Merlin.Visible) {
  AgentIntro()
                 //HideReq = Merlin.Hide();
        }
        else {

          AgentControl.Characters.Character.Unload(MerlinID);
        }
    }
//-->
</SCRIPT>

<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="Microsoft FrontPage 6.0" name=GENERATOR></HEAD>
<BODY style="BACKGROUND-COLOR: #ffffff" bgColor=#ffffff >
 </BODY></HTML>

0 0

相关博文

我的热门文章

img
取 消
img