MS Speech SAPI Text to speech COM (Windows only)

Share your advanced PureBasic knowledge/code with the community.
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

The example now does what I suggested above: it plays a thunderbolt sound at the appropriate position. The file thunder1.wav is needed for this purpose. Please download it here: http://www.kanzlei-reumschuessel.de/thunder1.zip (copy this link and paste it in a new browser window if the download fails here on this page)
Last edited by Jens-Arne on Sun Jan 19, 2025 3:55 pm, edited 1 time in total.
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

gurj wrote: Sun Jan 19, 2025 3:46 pm thanks!
Can you increase the function: Automatically select the word being read.
What exactly do you mean by this? Do you want to fast forward to a given word or what else should trigger a selection of which word?
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by gurj »

reading word.
my pb for chinese:
http://ataorj.ys168.com
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

Ok, I think I got it now.

The new version of the pbi and the example highlights the word in the EditorGadget that is currently being read out as long as the corresponding checkbox is ticked. I think that was what you meant, right? There are two new functions for this purpose: sapi_GetCurrentWordPos and sapi_GetCurrentWordLen. With the former you have to state via the one and only parameter whether the chr(13) characters in the text should be subtracted from the position. This is neccessary for the example program so the parameter is 1.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by gurj »

ButtonGadget(...,"Say text") should acquiesce start from Current CursorPos.
my pb for chinese:
http://ataorj.ys168.com
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

That is not in the scope of the project. You can do that yourself by harnessing the return from the #EM_GETSEL message. Use that, copy the portion of the text you need with mid(...) and hand that over to sapi_Say.

The reason for this is that the project reads out text from a string. How the string gets there is up to the programmer. It might be from an EditorGadget, it might also very well be from somewhere completely else. So even the last change of the example program with highlighted words was out of scope, so to speak.
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by jak64 »

Hello Jens-Arne,
Many thanks again for the wonderful work on speech synthesis!

I use it in a program, it works great but I noticed that sometimes the sapi_IsVoiceRunning() function returns 0 while a text is being read.

I don't understand why.

Do you have any idea about this? (I looked at the code of sapi-all.pbi but I'm not competent enough to diagnose)

Thank you for your help
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

Hello jak64,

the only issue I can see is that at the very beginning of a new readout (but only after another one has stopped before) there is a brief "flicker" of the IsVoiceRunning flag (1 --> 0 --> 1). This must have been what you detected. I've gotten rid of this behaviour by purging all unprocessed SAPI events in sapi_Stop() [sapi-all.pbi has changed]. Please test again - I hope there are no issues anymore with sapi_IsVoiceRunning().
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by jak64 »

Hello Jens-Arne,

TOO, TOO STRONG!!!

Indeed, the problem arose when I voluntarily stopped a reading (in my game, if the person playing does not want to hear all the rules of the game, if they already know them, they can click on Next and therefore stop the current reading)

I registered the new version of sapi-all-pbi and everything is OK now.

I invite everyone who uses this module to copy it again to benefit from Jens-Arne's correction.

Many thanks again Jens-Arne.

ps: I don't know if what I write is correct because, being French, I use Google translate...
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

Hello jak64,

your text is perfect. Google translate does what it is supposed to do... ;-)
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by gurj »

How:fast forward to a given word ?
Last edited by gurj on Tue Feb 25, 2025 9:55 pm, edited 1 time in total.
my pb for chinese:
http://ataorj.ys168.com
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

That's not possible at the moment. You would have to select the appropriate part of the text in your program and start reading from the point where it should begin.
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by jak64 »

Hello Jens-Arne,
I use your speech synthesis program and, as I already wrote to you, a big thank you to you, it works perfectly with the addition you made so that the module does not return 0 unexpectedly.

I will ask a question but maybe you can't answer it.

I program PuraBasic under Windows 11. Is it possible to have an equivalent program, using speech synthesis with an Apple tablet?

Thanks to all those who could inform me on this subject.
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

Hello jak64,

that's certainly not possible with the code that is in use here. It relies solely on a certain Windows COM Interface that is unique to Windows.

I don't code for machines that have an apple that's already missing a bite printed on them so I have no idea how to use speech synthesis on Apple devices, sorry.
Jens-Arne
User
User
Posts: 43
Joined: Sun Feb 04, 2024 11:09 am

Re: MS Speech SAPI Text to speech COM (Windows only)

Post by Jens-Arne »

Hello jak64,

that's certainly not possible with the code that is in use here. It relies solely on a certain Windows COM interface that is unique to Windows.

I don't code for machines that have an apple that's already missing a bite printed on them so I have no idea how to use speech synthesis on Apple devices, sorry.
Last edited by Jens-Arne on Wed Mar 05, 2025 9:50 pm, edited 1 time in total.
Post Reply