How to implent the MS Speech API in console environment

I just recently found out how to use the MS Speech API in a VCL-Form application :
[b]
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
voice: OLEVariant;
begin
voice := CreateOLEObject('SAPI.SpVoice');
voice.Speak('Hello World!', 0);
end;

end.
[/b]



I then tryed to use the MS Speech API in a Console Application to make it accessable via Batch
something like this :[b] this is example code
pause
consolespeech Hello World
pause
[/b]

The problem is that simply copining the code into the console application doesn't work. This is my code :
[b]
program Project1;

{$APPTYPE CONSOLE}

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



var
voice: OLEVariant;
a: OLEVariant;
begin
read(a);
if a='speak' then voice.speak('Hi',0);

voice := CreateOLEObject('SAPI.SpVoice');

end.
[/b]

Could someone help me please?


Just a little question in advance:

How can I make the Delphi application get data from the .BAT file:
[b]
consolespeech Hello World
-----------
How can I make the application retrieve the 'Hello World' and speak it out aloud.




Thanks in advance :)

Comments

  • : I just recently found out how to use the MS Speech API in a VCL-Form application :
    : [b]
    : unit Unit1;
    :
    : interface
    :
    : uses
    : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : Dialogs, Comobj, StdCtrls;
    :
    : type
    : TForm1 = class(TForm)
    : Button1: TButton;
    : procedure Button1Click(Sender: TObject);
    : private
    : { Private-Deklarationen }
    : public
    : { Public-Deklarationen }
    : end;
    :
    : var
    : Form1: TForm1;
    :
    : implementation
    :
    : {$R *.dfm}
    :
    : procedure TForm1.Button1Click(Sender: TObject);
    : var
    : voice: OLEVariant;
    : begin
    : voice := CreateOLEObject('SAPI.SpVoice');
    : voice.Speak('Hello World!', 0);
    : end;
    :
    : end.
    : [/b]
    :
    :
    :
    : I then tryed to use the MS Speech API in a Console Application to make it accessable via Batch
    : something like this :[b] this is example code
    : pause
    : consolespeech Hello World
    : pause
    : [/b]
    :
    : The problem is that simply copining the code into the console application doesn't work. This is my code :
    : [code]
    : program Project1;
    :
    : {$APPTYPE CONSOLE}
    :
    : uses
    : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : Dialogs, Comobj, StdCtrls;
    :
    :
    :
    : var
    : voice: OLEVariant;
    : a: OLEVariant;
    : begin
    : read(a);
    : [red]if a='speak' then voice.speak('Hi',0);
    :
    : voice := CreateOLEObject('SAPI.SpVoice');[/red]
    :
    : end.
    : [/code]
    :
    : Could someone help me please?
    :
    :
    : Just a little question in advance:
    :
    : How can I make the Delphi application get data from the .BAT file:
    : [b]
    : consolespeech Hello World
    : -----------
    : How can I make the application retrieve the 'Hello World' and speak it out aloud.
    :
    :
    :
    :
    : Thanks in advance :)
    :
    :
    The ParamCount() and ParamStr() functions can be used to get the command-line parameters. In your console application you first speak the words then create the object (see the red part).
  • : : I just recently found out how to use the MS Speech API in a VCL-Form application :
    : : [b]
    : : unit Unit1;
    : :
    : : interface
    : :
    : : uses
    : : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : : Dialogs, Comobj, StdCtrls;
    : :
    : : type
    : : TForm1 = class(TForm)
    : : Button1: TButton;
    : : procedure Button1Click(Sender: TObject);
    : : private
    : : { Private-Deklarationen }
    : : public
    : : { Public-Deklarationen }
    : : end;
    : :
    : : var
    : : Form1: TForm1;
    : :
    : : implementation
    : :
    : : {$R *.dfm}
    : :
    : : procedure TForm1.Button1Click(Sender: TObject);
    : : var
    : : voice: OLEVariant;
    : : begin
    : : voice := CreateOLEObject('SAPI.SpVoice');
    : : voice.Speak('Hello World!', 0);
    : : end;
    : :
    : : end.
    : : [/b]
    : :
    : :
    : :
    : : I then tryed to use the MS Speech API in a Console Application to make it accessable via Batch
    : : something like this :[b] this is example code
    : : pause
    : : consolespeech Hello World
    : : pause
    : : [/b]
    : :
    : : The problem is that simply copining the code into the console application doesn't work. This is my code :
    : : [code]
    : : program Project1;
    : :
    : : {$APPTYPE CONSOLE}
    : :
    : : uses
    : : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : : Dialogs, Comobj, StdCtrls;
    : :
    : :
    : :
    : : var
    : : voice: OLEVariant;
    : : a: OLEVariant;
    : : begin
    : : read(a);
    : : [red]if a='speak' then voice.speak('Hi',0);
    : :
    : : voice := CreateOLEObject('SAPI.SpVoice');[/red]
    : :
    : : end.
    : : [/code]
    : :
    : : Could someone help me please?
    : :
    : :
    : : Just a little question in advance:
    : :
    : : How can I make the Delphi application get data from the .BAT file:
    : : [b]
    : : consolespeech Hello World
    : : -----------
    : : How can I make the application retrieve the 'Hello World' and speak it out aloud.
    : :
    : :
    : :
    : :
    : : Thanks in advance :)
    : :
    : :
    : The ParamCount() and ParamStr() functions can be used to get the command-line parameters. In your console application you first speak the words then create the object (see the red part).
    :


    Thank you I oversaw that mistake, but the problem still exists.
    If I try to execute the application it tells me that COInitialize wasn't loaded.
    Please help me.
  • : : : I just recently found out how to use the MS Speech API in a VCL-Form application :
    : : : [b]
    : : : unit Unit1;
    : : :
    : : : interface
    : : :
    : : : uses
    : : : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : : : Dialogs, Comobj, StdCtrls;
    : : :
    : : : type
    : : : TForm1 = class(TForm)
    : : : Button1: TButton;
    : : : procedure Button1Click(Sender: TObject);
    : : : private
    : : : { Private-Deklarationen }
    : : : public
    : : : { Public-Deklarationen }
    : : : end;
    : : :
    : : : var
    : : : Form1: TForm1;
    : : :
    : : : implementation
    : : :
    : : : {$R *.dfm}
    : : :
    : : : procedure TForm1.Button1Click(Sender: TObject);
    : : : var
    : : : voice: OLEVariant;
    : : : begin
    : : : voice := CreateOLEObject('SAPI.SpVoice');
    : : : voice.Speak('Hello World!', 0);
    : : : end;
    : : :
    : : : end.
    : : : [/b]
    : : :
    : : :
    : : :
    : : : I then tryed to use the MS Speech API in a Console Application to make it accessable via Batch
    : : : something like this :[b] this is example code
    : : : pause
    : : : consolespeech Hello World
    : : : pause
    : : : [/b]
    : : :
    : : : The problem is that simply copining the code into the console application doesn't work. This is my code :
    : : : [code]
    : : : program Project1;
    : : :
    : : : {$APPTYPE CONSOLE}
    : : :
    : : : uses
    : : : Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    : : : Dialogs, Comobj, StdCtrls;
    : : :
    : : :
    : : :
    : : : var
    : : : voice: OLEVariant;
    : : : a: OLEVariant;
    : : : begin
    : : : read(a);
    : : : [red]if a='speak' then voice.speak('Hi',0);
    : : :
    : : : voice := CreateOLEObject('SAPI.SpVoice');[/red]
    : : :
    : : : end.
    : : : [/code]
    : : :
    : : : Could someone help me please?
    : : :
    : : :
    : : : Just a little question in advance:
    : : :
    : : : How can I make the Delphi application get data from the .BAT file:
    : : : [b]
    : : : consolespeech Hello World
    : : : -----------
    : : : How can I make the application retrieve the 'Hello World' and speak it out aloud.
    : : :
    : : :
    : : :
    : : :
    : : : Thanks in advance :)
    : : :
    : : :
    : : The ParamCount() and ParamStr() functions can be used to get the command-line parameters. In your console application you first speak the words then create the object (see the red part).
    : :
    :
    :
    : Thank you I oversaw that mistake, but the problem still exists.
    : If I try to execute the application it tells me that COInitialize wasn't loaded.
    : Please help me.
    :
    Then you need to call CoIntitialize().
  • Thanks a lot :)

    For everyone who wants to know :

    uses ActiveX;
    var voice : OleVariant;
    begin
    CoInitialize(nil);
    voice := CreateOLEObject('SAPI.SpVoice');
    voice.speak('Hello WOrld',0);
    CoUnInitialize;
    end
  • Thanks a lot :)

    For everyone who wants to know :

    uses ActiveX;
    var voice : OleVariant;
    begin
    CoInitialize(nil);
    voice := CreateOLEObject('SAPI.SpVoice');
    voice.speak('Hello WOrld',0);
    CoUnInitialize;
    end
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories