Skip to content

Instantly share code, notes, and snippets.

@ayoub-9
Last active January 19, 2019 13:01
Show Gist options
  • Save ayoub-9/a94bf44f4858b61325b6a158d2f732ff to your computer and use it in GitHub Desktop.
Save ayoub-9/a94bf44f4858b61325b6a158d2f732ff to your computer and use it in GitHub Desktop.
import UIKit
import AVFoundation
class ViewController: UIViewController{
@IBOutlet weak var sliderVolume: UISlider! //for volume
let speechSynth = AVSpeechSynthesizer()
@IBAction func btnStartToSpeak(_ sender: UIButton) {
let speechUtt = AVSpeechUtterance(string: "Hello")
// speechUtt.rate = self.sliderRate.value
speechUtt.volume = self.sliderVolume.value
// speechUtt.pitchMultiplier = self.sliderPitch.value
self.speechSynth.speak(speechUtt)
}
}
---------------------------------------
another and best code to speech text with any Language
-------------------------------------------------------
import UIKit
import AVFoundation
class ViewController: UIViewController, AVSpeechSynthesizerDelegate {
@IBOutlet weak var sliderRate: UISlider! //for rate
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func buttonPushed(sender: UIButton) {
let utterance = AVSpeechUtterance(string:"채소는 건강에 좋아요")
utterance.voice = AVSpeechSynthesisVoice(language: "ko-KR")
let voice = AVSpeechSynthesizer()
voice.delegate = self
utterance.rate = self.sliderRate.value
voice.speak(utterance)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment