Page 1 of 1

MacOS espeak

Posted: Tue Aug 29, 2023 9:03 am
by michel
Hello,

Is it possible to use Espeak within a purebasic windowprogram (not a console application) on the mac platform?

Michel

Re: MacOS espeak

Posted: Tue Aug 29, 2023 1:22 pm
by deseven
I don' t see why not and it doesn't matter if you want to use it in a console or windowed app. Espeak has a command line interface, just use RunProgram() and all related stuff to call it and pass any text you like.

Re: MacOS espeak

Posted: Tue Aug 29, 2023 3:36 pm
by michel
Hello,

You mentioned it: the related stuff is the problem

Michel

Re: MacOS espeak

Posted: Tue Aug 29, 2023 3:52 pm
by deseven
https://www.purebasic.com/documentation ... index.html

Code: Select all

#synthesizerPath = "/opt/homebrew/bin/espeak" ; path to your espeak, you can also use /usr/bin/say which is included in macOS by default

Procedure say(text.s)
  synthesizer = RunProgram(#synthesizerPath,"",GetEnvironmentVariable("HOME"),#PB_Program_Open|#PB_Program_Write)
  If synthesizer
    WriteProgramStringN(synthesizer,text)
    WriteProgramData(synthesizer,#PB_Program_Eof,0)
    CloseProgram(synthesizer)
  EndIf
EndProcedure

OpenWindow(0,0,0,400,300,"Voice Synthesizer Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
EditorGadget(0,10,10,380,240,#PB_Editor_WordWrap)
ButtonGadget(1,10,260,380,30,"synthesize")

Repeat
  ev = WaitWindowEvent()
  If ev = #PB_Event_Gadget And EventGadget() = 1
    say(GetGadgetText(0))
  EndIf
Until ev = #PB_Event_CloseWindow

Re: MacOS espeak

Posted: Tue Aug 29, 2023 4:56 pm
by Piero
Making the computer's speech sound better

You can make the computer's speech sound more natural using punctuation to add pauses and terms to remove unnecessary emphasis.

Adding pauses:
To add a pause to a spoken line:
– Insert a comma where you want a pause to occur.
For example:

Code: Select all

say "You have a meeting, next Monday at 3:30, in room 57."
To add a shorter pause before and after a phrase:
– Put single quotation marks around the phrase.
For example:

Code: Select all

say "The file 'status report' has been printed."
Adding emphasis:
To add emphasis to a word:
– Insert [[emph +]] before the word.
For example:

Code: Select all

say "I [[emph +]] love my Mac."
Removing unneeded emphasis:
To remove emphasis from a word:
– Insert [[emph -]] before the word.
For example:

Code: Select all

say "Five [[emph -]] documents were printed, and three were [[emph -]] copied to backup."
Emphasis is automatically removed from common short words such as "to," "and," "were," and "the."

Image

This is Applescript: see viewtopic.php?p=605929#p605929

Re: MacOS espeak

Posted: Tue Aug 29, 2023 5:37 pm
by michel
Many thanks to your support

Michel :D

Re: MacOS espeak

Posted: Thu Aug 31, 2023 1:25 pm
by mk-soft
Direct with Siri voice ...

Code: Select all

Global SpeechSynthesizer = CocoaMessage(0, CocoaMessage(0, 0, "NSSpeechSynthesizer alloc"), "initWithVoice:", #nil)
Global voice.s = "com.apple.speech.synthesis.voice.siri"

CocoaMessage(0, SpeechSynthesizer, "setVoice:$", @voice)
CocoaMessage(0, SpeechSynthesizer, "startSpeakingString:$", @"Hello, I like purebasic")
If OpenWindow(0, 0, 0, 200, 30, "Hallo", #PB_Window_SystemMenu)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: MacOS espeak

Posted: Thu Aug 31, 2023 5:27 pm
by Shardik
You should also try out wilbert's two speech synthesizer examples using the Speech Synthesis Manager (just successfully tested with MacOS 11.7.9 'Big Sur'). The speech quality is much better than in mk-soft's Siri example.

Re: MacOS espeak

Posted: Sun Sep 03, 2023 11:17 am
by Piero
michel wrote: Tue Aug 29, 2023 5:37 pm Many thanks to your support
Michel :D
You are very welcome!

PS: if you want to get fired (while trying to send a colleague to psychiatric hospital) learn how to login to other Macs on the local network, then use the "Whisper" voice…