Last active
January 19, 2019 13:01
-
-
Save ayoub-9/a94bf44f4858b61325b6a158d2f732ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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