Page updated Jan 16, 2024

Transcribe audio to text

Amplify iOS v1 is now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Swift to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for iOS, you can access the documentation here.

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 and select Convert. Then use the following answers:

1? What would you like to convert?
2 Translate text into a different language
3 Generate speech audio from text
4❯ Transcribe text from audio
5
6? Provide a friendly name for your resource
7 <Enter a friendly name here>
8
9? What is the source language? (Use arrow keys)
10 <Select your default source language>
11
12? Who should have access?
13 Auth users only
14❯ Auth and Guest users

Working with the API

Here is an example of converting speech to text. In order to override any choices you made while adding this resource using the Amplify CLI, you can pass in a language in the options object as shown below.

1func speechToText(speech: URL) {
2 let options = PredictionsSpeechToTextRequest.Options(
3 defaultNetworkPolicy: .auto,
4 language: .usEnglish,
5 pluginOptions: nil
6 )
7
8 Amplify.Predictions.convert(speechToText: speech, options: options) { event in
9 switch event {
10 case let .success(result):
11 print(result.transcription)
12 case let .failure(error):
13 print(error)
14 }
15 }
16}
1func speechToText(speech: URL) -> AnyCancellable {
2 let options = PredictionsSpeechToTextRequest.Options(
3 defaultNetworkPolicy: .auto,
4 language: .usEnglish,
5 pluginOptions: nil
6 )
7
8 let sink = Amplify.Predictions.convert(speechToText: speech, options: options)
9 .resultPublisher
10 .sink {
11 if case let .failure(error) = $0 {
12 print(error)
13 }
14 }
15 receiveValue: { result in
16 print(result.transcription)
17 }
18 return sink
19}