Page 1 of 1

Assistant package question

PostPosted: June 20th, 2006, 1:26 am
by sfpx
First, thank you for this excellent component !

Now, here is my stupid question.

How do we make the assistant to speak a sequence of strings ?
Let's say I want the assistant to say "Hello" then pause for about 2 seconds and then say "Welcome to my program".

I tried many things but couldn't get it to work. I always only see the last sentence.

PostPosted: June 21st, 2006, 6:05 pm
by Kambiz
The office assistant package is not speech enabled. You have to use a third-party component for this purpose.

PostPosted: June 21st, 2006, 8:11 pm
by sfpx
Sorry I explained my problem badly.
I meant to "speak" with the balloon text.
One balloon saying "Hello" then 2 seconds later saying"welcome "

PostPosted: June 21st, 2006, 10:40 pm
by Kambiz
It was my fault not reading the question carefully, sorry.

I hope the following piece of code helps.

Code: Select all
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, oaTypes, StdCtrls, oaAssist;

const
  WM_SAYNEXTPART = WM_USER + 1;

type
  TForm1 = class(TForm)
    Assistant1: TAssistant;
    Memo1: TMemo;
    Button1: TButton;
    procedure Assistant1BalloonHide(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    SpeakIndex: Integer;
    procedure WMSayNextPaty(var Msg: TMessage); message WM_SAYNEXTPART;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Assistant1BalloonHide(Sender: TObject);
begin
  PostMessage(Handle, WM_SAYNEXTPART, 0, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SpeakIndex := -1;
  PostMessage(Handle, WM_SAYNEXTPART, 0, 0);
end;

procedure TForm1.WMSayNextPaty(var Msg: TMessage);
begin
  Inc(SpeakIndex);
  if SpeakIndex < Memo1.Lines.Count then
    Assistant1.Speak(Memo1.Lines[SpeakIndex], 2000);
end;

end.

PostPosted: June 22nd, 2006, 6:06 pm
by sfpx
Thanks for the code but unfortunately it doesn't work exactly like I want.

Of course if I click on the button that executes
PostMessage(Handle, WM_SAYNEXTPART, 0, 0);
many times I'll get a sequence of balloons.

But I want the sequence to be launched in a procedure. Your code works because the user ends up doing the job of "pausing" between the messages.

Let's say for example that in the button onclick event we have


Code: Select all
procedure TForm1.Assistant1BalloonHide(Sender: TObject);
var i:integer;
begin
  for i:= 0 to memo1.Lines.Count-1 do PostMessage(Handle, WM_SAYNEXTPART, 0, 0);

end;


Then only the last line will be displayed

PostPosted: June 22nd, 2006, 8:18 pm
by Kambiz
What I wrote, was somthing as a hint.

Of course you might not use a for-loop to post several messages on the message queue. You should use a timer and control the timer using the OnBalloonHide event.

PostPosted: June 23rd, 2006, 1:06 am
by sfpx
I'm just an idiot ;)
I badly implemented the code you gave me.
It actually works.

Thank you again