MacOS espeak

Mac OSX specific forum
michel
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Feb 19, 2007 5:47 pm
Location: Luxemburg

MacOS espeak

Post by michel »

Hello,

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

Michel
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: MacOS espeak

Post 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.
michel
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Feb 19, 2007 5:47 pm
Location: Luxemburg

Re: MacOS espeak

Post by michel »

Hello,

You mentioned it: the related stuff is the problem

Michel
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: MacOS espeak

Post 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
User avatar
Piero
Addict
Addict
Posts: 885
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: MacOS espeak

Post 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
michel
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Feb 19, 2007 5:47 pm
Location: Luxemburg

Re: MacOS espeak

Post by michel »

Many thanks to your support

Michel :D
User avatar
mk-soft
Always Here
Always Here
Posts: 6226
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: MacOS espeak

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: MacOS espeak

Post 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.
User avatar
Piero
Addict
Addict
Posts: 885
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: MacOS espeak

Post 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…
 
Post Reply