Speech Synthesis

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Speech Synthesis

Post by wilbert »

I experimented a bit with the OSX speech synthesis function.
Maybe someone can use this, maybe not :wink:
The code below speaks a smal text with a random selected voice.

Code: Select all

Structure VoiceSpec
  creator.l
  id.l
EndStructure

ImportC "/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices"
  CountVoices (*numVoices.w)
  DisposeSpeechChannel (chan)
  GetIndVoice (index.w, *voice)
  NewSpeechChannel (*voice, *chan)
  SpeakText (chan, *textBuf, textBytes.l)
  SpeechBusy.w ()
EndImport

CountVoices(@numVoices.w)
index.w = Random(numVoices - 1) + 1

GetIndVoice(index, Voice.VoiceSpec)
NewSpeechChannel(Voice, @chan)

Text.s = "PureBasic speech on OSX"

SpeakText(chan, @Text, Len(Text))

Repeat
  Delay(100)
Until SpeechBusy() = #False

DisposeSpeechChannel(chan)
jamirokwai
Enthusiast
Enthusiast
Posts: 772
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Speech Synthesis

Post by jamirokwai »

wilbert wrote:I experimented a bit with the OSX speech synthesis function.
Maybe someone can use this, maybe not :wink:
The code below speaks a smal text with a random selected voice.
Nice finding, wilbert!
Regards,
JamiroKwai
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Speech Synthesis

Post by jesperbrannmark »

Another suggestion:

Code: Select all

COCOA_AppleScript("say "+Chr(34)+"Purebasic applescript rules"+Chr(34)+" using "+Chr(34)+"cellos"+Chr(34))
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Speech Synthesis

Post by WilliamL »

COCOA_AppleScript("say "+Chr(34)+"Purebasic applescript rules"+Chr(34)+" using "+Chr(34)+"cellos"+Chr(34))
Tell me again how to use this?
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Speech Synthesis

Post by jesperbrannmark »

You need the Applescript wrapper in your applications/purebasic/libraries/userlibraries folder.
You will find it in the forum http://www.purebasic.fr/english/viewtop ... 19&t=40684.
Its excellent in many ways to communicate with the "outside world". The latest version of it also runs threadsafe... A piece of magic :-)
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Speech Synthesis

Post by WilliamL »

Thanks jasper!

That works!

I'm curious, which files are actually needed in the userlibraries? (build.command/libPBCoca_x86/libPBCocoa.desc) A dumb question, what commands are available thru AppleScript and where do I find them?

I wonder if AppleScript would be an easy way to print (text)?

Looks like I am going to be reading up on AppleScript!
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
Post Reply