Recent

Author Topic: [Solved]Win7 Sapi Problem  (Read 8628 times)

codeman

  • Jr. Member
  • **
  • Posts: 78
[Solved]Win7 Sapi Problem
« on: August 14, 2012, 07:06:40 pm »
Hello , when i click an image to my program on win7 x32 i get the below error 
(It works fine on WinXP with no errors ..)

Image
Code: [Select]
http://desmond.imageshack.us/Himg39/scaled.php?server=39&filename=errordh.jpg&res=landing


The Code:
Code: [Select]
var
    SpVoice: Variant;
begin
    SpVoice := CreateOleObject('SAPI.SpVoice');
    SpVoice.Speak('hi', 0);



?

« Last Edit: August 14, 2012, 11:48:53 pm by codeman »
Lazarus v2.02 Win10

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Win7 Sapi Problem
« Reply #1 on: August 14, 2012, 08:28:46 pm »
That is a known problem with the fpu interrupt mask. See http://stackoverflow.com/questions/3032739/delphi-sapi-text-to-speech (the Update in the bottom of the first post) for the solution. Happens with sapi only on vista and later but the fpu interrupt mask is a regular problem on all windows system when using dll's that use the fpu. Freepascal and Delphi use a different interrupt mask than C and C++ and will catch floating point errors that C/C++ would not handle with exceptions.

codeman

  • Jr. Member
  • **
  • Posts: 78
Re: Win7 Sapi Problem
« Reply #2 on: August 14, 2012, 11:48:28 pm »
Thanks for your help mate. It works now
Lazarus v2.02 Win10

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [Solved]Win7 Sapi Problem
« Reply #3 on: August 15, 2012, 11:24:37 am »
I've created a wiki page with part of the code from this thread and the stackoverflow page.
http://wiki.lazarus.freepascal.org/SAPI

I'd appreciate corrections/additions (anyone can edit the wiki)- it might be useful for other users as well..

Thanks,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

nsunny

  • Full Member
  • ***
  • Posts: 117
  • Code is magic
    • LazPlanet
Re: [Solved]Win7 Sapi Problem
« Reply #4 on: March 06, 2013, 02:22:42 am »
Thanks to BigChimp for the wiki and others for info as well.

I have found another variation of the  code posted on the wiki. The wiki sends a static text ('hi') to SpVoice.Speak() call. But I wanted to send dynamic text to the TTS engine. For example, reading the current time.

First I tried with a string, then many other things (even StringToOleStr) but no luck. But Finally I found a solution. The trick is to create a WideString, instead of a String/AnsiString. Here is a code that reads the current time  8-) :

Code: [Select]
uses ... , comobj;

var
  SavedCW: Word;
  SpVoice: Variant;

  myWideString : WideString;
begin
  SpVoice := CreateOleObject('SAPI.SpVoice');
  // Change FPU interrupt mask to avoid SIGFPE exceptions
  SavedCW := Get8087CW;

  // Store in the WideChar what needs to be read
  myWideString  := 'Hello, the time is ' + TimeToStr(Time);

  try
    Set8087CW(SavedCW or $4);
    // We send our created WideString to Speak() call
    SpVoice.Speak(myWideString, 0);
  finally
    // Restore FPU mask
    Set8087CW(SavedCW);
  end;

Lazarus TTS Tutorial | LazPlanet
Lazarus 2.2.0 | FPC 3.2.2 | Linux/OpenBSD/ReactOS

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [Solved]Win7 Sapi Problem
« Reply #5 on: March 06, 2013, 08:04:53 am »
Nice.
Additions to the wiki are welcome so we keep as much info in one place as possible :)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018