@State private var inputString = "Hello world! My name is Dev Techie"
struct TextToSpeechExample: View { @State private var inputString = "Hello world! My name is Dev Techie" var body: some View { VStack { TextField("Enter text", text: $inputString) .textFieldStyle(.roundedBorder) Button("Text to speech") { // add utterance here } }.padding() } }
let utterance = AVSpeechUtterance(string: inputString)
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
utterance.pitchMultiplier = 2.0 utterance.rate = 0.3
let synthesizer = AVSpeechSynthesizer() synthesizer.speak(utterance)
struct TextToSpeechExample: View { @State private var inputString = "Hello world! My name is Dev Techie" var body: some View { VStack { TextField("Enter text", text: $inputString) .textFieldStyle(.roundedBorder) Button("Text to speech") { let utterance = AVSpeechUtterance(string: inputString) utterance.voice = AVSpeechSynthesisVoice(language: "en-US") utterance.pitchMultiplier = 2.0 utterance.rate = 0.3 let synthesizer = AVSpeechSynthesizer() synthesizer.speak(utterance) } }.padding() } }
With that we have reached the end of this article. Thank you once again for reading. Don’t forget to subscribe our weekly newsletter at https://www.devtechie.com