## Set up the backend If you haven't already done so, run `amplify init` inside your project and then `amplify add auth` (we recommend selecting the *default configuration*). Run `amplify add predictions`, then use the following answers: ```console ? Please select from one of the categories below Identify ❯ Convert Interpret Infer Learn More ? What would you like to convert? Translate text into a different language ❯ Generate speech audio from text Transcribe text from audio ? Provide a friendly name for your resource ? What is the source language? (Use arrow keys) ? Who should have access? Auth users only ❯ Auth and Guest users ``` Run `amplify push` to create the resources in the cloud ## Working with the API Here is an example of converting text to speech. In order to override any choices you made while adding this resource using the Amplify CLI, you can pass in a voice in the options object as shown below. ```swift import Amplify import AWSPredictionsPlugin import AVFoundation //... var player: AVAudioPlayer? //... func textToSpeech() async throws { let result = try await Amplify.Predictions.convert( .textToSpeech("Hello, world!"), options: .init(voice: .englishFemaleIvy) ) print("TextToSpeech result: \(result)") self.player = try AVAudioPlayer(data: result.audioData) player?.play() } ``` ```swift import Amplify import AWSPredictionsPlugin import AVFoundation //... var player: AVAudioPlayer? var textToSpeechSink: AnyCancellable? //... func textToSpeech() { textToSpeechSink = Amplify.Publisher.create { try await Amplify.Predictions.convert( .textToSpeech("Hello, world!"), options: .init(voice: .englishFemaleIvy) ) } .sink(receiveCompletion: { completion in if case let .failure(error) = completion { print("Error converting text to speech: \(error)") } }, receiveValue: { result in print("TextToSpeech result: \(result)") self.player = try? AVAudioPlayer(data: result.audioData) self.player?.play() }) } ``` As a result of running this code, you will hear audio of the text being emitted from your device.