PDA

View Full Version : Type Library - MS Speech API 5.0



NecroDOME
01-11-2006, 01:05 PM
I imported a type lib (Speech API 5.0 from MS) into Delphi. It created an unit for it I can use, but it doesn't create the components. In Delphi 7 I have nice components I can drop onto my form.

Are they located somewhere else? Need I need to make the manually?

JernejL
01-11-2006, 04:25 PM
I imported a type lib (Speech API 5.0 from MS) into Delphi. It created an unit for it I can use, but it doesn't create the components. In Delphi 7 I have nice components I can drop onto my form.

Are they located somewhere else? Need I need to make the manually?

i read somewhere than D6 has broken typelib importer, use unit from D7 or D5.

NecroDOME
01-11-2006, 06:43 PM
I got Delphi 2005... sorry for not mentioning...

JernejL
01-11-2006, 07:07 PM
strange, maybe they broke something again :/

NecroDOME
01-11-2006, 07:13 PM
Well... I could downgrade to Delphi 7, but i'll try to call it manually.

JernejL
01-11-2006, 07:23 PM
By the way, has anybody gotten the sapi 5.1 to work and save the playback stream to a wave file? in theory this should work:


var
SpVoice: Variant;
SPFS: Variant;
begin

SPFS:= CreateOleObject('SAPI.SpFileStream');
SPFS.format.type:= 6;
SPFS.open('c:\test.wav', SSFMCreateForWrite {6});

SpVoice:= CreateOleObject('SAPI.SpVoice');
SpVoice.AudioOutputStream:= SPFS;

SpVoice.Speak('ROFL!', SVSFDefault);
SPFS.close;

But i get a member not found error for SpVoice.AudioOutputStream... any ideas? i am trying to implement SAPI for use with openal, and i need to store wave streams to file or memory to get them into openal, but nothing of this work..

NecroDOME
01-11-2006, 07:45 PM
I once made a chat program with the speech API in delphi 7. Bit stupid the talk to your computer while it responds with some stupid answers :P

chrila
02-12-2006, 08:13 AM
create spvoice component on your form and click true for autoconnect propertie
...
public
procedure SavewaveFile(filename: string;itext:string);
....

procedure TForm4.SavewaveFile(filename: string;itext:string);
var
TSW: TSpFileStream;
begin
TSW:=TSpFileStream.Create(self);
TSW.Open(filename, SSFMcreateForWrite, false);
SpVoice.AudioOutputStream:=TSW.DefaultInterface;
Spvoice.Speak(itext, SVSFDefault);
TSW.Close;
end;

JernejL
02-12-2006, 11:32 AM
create spvoice component on your form and click true for autoconnect propertie
...
public
procedure SavewaveFile(filename: string;itext:string);
....

procedure TForm4.SavewaveFile(filename: string;itext:string);
var
TSW: TSpFileStream;
begin
TSW:=TSpFileStream.Create(self);
TSW.Open(filename, SSFMcreateForWrite, false);
SpVoice.AudioOutputStream:=TSW.DefaultInterface;
Spvoice.Speak(itext, SVSFDefault);
TSW.Close;
end;

can i have the header that you use? D4 does not create objects using this and TSpFileStream is undeclared, i have however tried the "DefaultInterface" method you shown with ole, and still get the same error. muyt be my outdated delphi version..

chrila
03-12-2006, 08:33 AM
Have you imported activex component from sapi ?
or imported type libraries? try twice
that's created component spvoice, etc...

here's my header :


unit Unit4;

//Uses SAPI 5.1 early bound Automation

interface

uses
ActiveX,
{$ifdef CONDITIONALEXPRESSIONS}
Variants,
{$endif}
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, ActnList, StdCtrls, ComCtrls, ToolWin, OleServer,
SpeechLib_TLB, Buttons, jpeg, ExtCtrls, ComObj;

type
TForm4 = class(TForm)
GroupBox1: TGroupBox;
Label2: TLabel;
Label7: TLabel;
cbVoices: TComboBox;
reText: TRichEdit;
BitBtn1: TBitBtn;
SpVoice: TSpVoice;
Image2: TImage;
savewav: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure cbVoicesChange(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure savewavClick(Sender: TObject);
private
public
filetospeak:string;
procedure SavewaveFile(filename: string;itext:string);
end;

var
form4: TForm4;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm4.FormCreate(Sender: TObject);
var
I: Integer;
SOToken: ISpeechObjectToken;
SOTokens: ISpeechObjectTokens;
begin
//Ensure all events fire
SpVoice.EventInterests := SVEAllEvents;
SOTokens := SpVoice.GetVoices('', '');
for I := 0 to SOTokens.Count - 1 do
begin
if (pos('Ellen',SOTokens.Item(i).id)>0) or
(pos('Virg',SOTokens.Item(i).id)>0) then
begin
//For each voice, store the descriptor in the TStrings list
SOToken := SOTokens.Item(I);
cbVoices.Items.AddObject(SOToken.GetDescription(0) , TObject(SOToken));
//Increment the descriptor reference count to ensure it doesn't get destroyed
SOToken._AddRef;
end
end;
if cbVoices.Items.Count > 0 then
begin
cbVoices.ItemIndex := 0; //Select 1st voice
cbVoices.OnChange(cbVoices); //& ensure OnChange triggers
end;
end;

procedure TForm4.FormDestroy(Sender: TObject);
var
I: Integer;
begin
//Release all the voice descriptors
for I := 0 to cbVoices.Items.Count - 1 do
ISpeechObjectToken(Pointer(cbVoices.Items.Objects[I]))._Release;
end;

procedure TForm4.cbVoicesChange(Sender: TObject);
var
SOToken: ISpeechObjectToken;
begin

SOToken := ISpeechObjectToken(Pointer(
cbVoices.Items.Objects[cbVoices.ItemIndex]));
SpVoice.Voice := SOToken;


end;

procedure TForm4.BitBtn1Click(Sender: TObject);
begin
SpVoice.Rate := 0;
SpVoice.Volume := form2.volume;
SpVoice.Speak(reText.Text, SVSFlagsAsync)
end;

procedure TForm4.savewavClick(Sender: TObject);
var i:integer;
f:string;
begin
SpVoice.Rate := 0;
SpVoice.Volume := form2.volume;
randomize();
i:=random(1000);
while i=0 do
i:=random(1000);
f:='d:\'+inttostr(i)+'tempwavfile.wav';
while fileexists(f) do
begin
i:=random(1000);
while i=0 do i:=random(1000);
f:='d:\'+inttostr(i)+'tempwavfile.wav';
end;
savewavefile(f,reText.text);
filetospeak:=f;


end;


procedure TForm4.SavewaveFile(filename: string;itext:string);
var
TSW: TSpFileStream;
begin
TSW:=TSpFileStream.Create(self);
TSW.Open(filename, SSFMcreateForWrite, false);
SpVoice.AudioOutputStream:=TSW.DefaultInterface;
Spvoice.Speak(itext, SVSFDefault);
TSW.Close;
end;



end.

chrila
03-12-2006, 08:41 AM
have you downloaded SAPI 5.1 SDK ?

chrila
03-12-2006, 08:50 AM
i work on delphi 7, but it seem's that work in all delphi version

WILL
03-12-2006, 09:18 AM
Whoa slow down there friend. :) You can 'Edit' your last post if you forgot something instead of having to make a new one.

Also, unique to PGD is the [pascal] tags (created by Ian 'BlueCat' Ashbury, one of the original pioneers of the PGD community) that allow you to display properly all your Pascal code with nice highlighting in these forums.

That said, welcome to PGD and please feel free to get to know the place. ;)