Page 1 of 1

Speech Synthesis

Posted: Mon Jan 04, 2010 8:08 am
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)

Re: Speech Synthesis

Posted: Mon Jan 04, 2010 10:38 am
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!

Re: Speech Synthesis

Posted: Wed Jun 22, 2011 9:28 am
by jesperbrannmark
Another suggestion:

Code: Select all

COCOA_AppleScript("say "+Chr(34)+"Purebasic applescript rules"+Chr(34)+" using "+Chr(34)+"cellos"+Chr(34))

Re: Speech Synthesis

Posted: Fri Jul 01, 2011 4:29 am
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?

Re: Speech Synthesis

Posted: Fri Jul 01, 2011 6:33 am
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 :-)

Re: Speech Synthesis

Posted: Fri Jul 01, 2011 3:38 pm
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!