user1581016
user1581016

Reputation: 81

SAPI - Each next phrase takes more time than previous

I'm working with MS SAPI in Delphi7. My goal is:

All works fine, but I see that each next phrase takes more time than previous (see screenshot). I don't understand this. Is there any way to change this behaviour?

uses ...SpeechLib_TLB...

procedure TForm1.Button2Click(Sender: TObject);
var
    SpVoice: TSpVoice;
    SpMemoryStream: TSpMemoryStream;
    SpFileStream: TSpFileStream;
    SavedCW: Word;
    i: integer;
    list: tstrings;
    time1, time2, bytes1, bytes2: dword;
begin
    ListBox1.Clear;
    list:=tstringlist.create;
    list.loadfromfile(extractfilepath(paramstr(0)) + 'test1.txt');

    SpVoice:=TSpVoice.create(nil);

    SpMemoryStream:=TSpMemoryStream.Create(nil);
    SpMemoryStream.Format.type_:=SAFT44kHz16BitMono;

    SpVoice.AudioOutputStream:=SpMemoryStream.DefaultInterface;

    SpFileStream:=TSpFilestream.Create(nil);
    SpFileStream.Format.type_:=SAFT44kHz16BitMono;
    SpFileStream.Open(ExtractFilePath(ParamStr(0))+'test1.wav', SSFMCreateForWrite, FALSE);

    SavedCW := Get8087CW;
    Set8087CW(SavedCW or $4);
    for i:=0 to list.count-1 do begin
        time1:=gettickcount;
        bytes1:=VarArrayHighBound(SpMemoryStream.GetData, 1);
        SpVoice.Speak(list[i], 0);
        time2:=gettickcount;
        bytes2:=VarArrayHighBound(SpMemoryStream.GetData, 1);
        ListBox1.items.Add(Format('%d ms   %d Bytes   %s', [time2-time1, bytes2-bytes1, list[i]]));
        Label1.caption:=format('Item %d From %d', [i+1, list.count]);
        Application.ProcessMessages;
    end;
    Set8087CW(SavedCW);

    SpFileStream.Write(SpMemoryStream.GetData);
    SpFileStream.Free;
    SpMemoryStream.Free;
    SpVoice.free;
    list.free;

    showmessage('All done');
end;

Output:

Upvotes: 0

Views: 113

Answers (0)

Related Questions