Page updated Jan 16, 2024

Transcribe audio to text

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(url: URL) async throws {
2 let options = Predictions.Convert.SpeechToText.Options(
3 defaultNetworkPolicy: .auto,
4 language: .usEnglish
5 )
6
7 let result = try await Amplify.Predictions.convert(
8 .speechToText(url: url), options: options
9 )
10
11 let transcription = result.map(\.transcription)
12
13 for try await transcriptionPart in transcription {
14 print("transcription part: \(transcriptionPart)")
15 }
16}