Ios text to speech

Is there a way for Xojo to convert text to speech in an IOS app?

System.Speak("Hello world")

If you want more control over the speech you can use AVFoundation in iOSKit - an example view is here: iOSKit/SpeechSynthesisView.xojo_code at master · kingj5/iOSKit · GitHub

1 Like

I’ve tried that exact line, but I get an error saying “this item doesn’t exist”

did you try Speak(“hello world”) ?

yes, that too. btw I’m currently using Xojo 2019 release 3.2 if that matters.

1 Like

If you are developing for iOS you really need to be on the latest version. I don’t think 2019r3.2 will be able to upload to the App Store at this point.

thanks for the info, but uploading to the app store is way in the future, and will never be necessary if I can’t get it to speak! I D/Led 2021r3 and still no joy.

The line System.Speak(“Hello world”) woks great in a desktop app, just not IOS. Maybe I could just carry an iMac around with me.

@Stephen_Schleick take a look at iOSKit - the AVFoundation classes can do what you want. If you are using 2019r3.2 for development you will need to use the API1-compatible branch. If you are using the latest (2021r3) then you can use the master branch

yes, I took a look at it earlier. Over 300 lines of code to replace one line that doesn’t work, but should? Is there a plug in required to us that?

No plugins needed, just copy the Modules folder from iOSKit into your project and it will be ready to go.

Unfortunately for iOS, some features are missing or not directly exposed. You will find that my iOSKit and @Jeremie_L 's iOSDesignExtensions (GitHub - jkleroy/iOSDesignExtensions: 100+ functions to extend iOSControls design) fill many of those needs

2 Likes

After importing iOSKit in your project, using Speech is fairly easy.

Dim speech As new AVFoundation.AVSpeechSynthesizer
Dim utterance as new AVFoundation.AVSpeechUtterance("Hello")

speech.SpeakUtterance(utterance)

And depending on how you want your app to Mix/Pause/Duck any other sounds such as music, add this in the App.Opening event

Dim setCategoryErr as Foundation.NSError

// https://developer.apple.com/documentation/avfaudio/avaudiosessioncategoryoptions
Dim avSession As AVFoundation.AVAudioSession = AVFoundation.AVAudioSession.SharedInstance
if not avSession.SetCategoryWithOptions("AVAudioSessionCategoryPlayback", AVFoundation.AVAudioSession.AVAudioSessionCategoryOptions.DuckOthers, setCategoryErr) then
  System.DebugLog("Error: Could not set audio category: " + setCategoryErr.localizedDescription)
end if

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.