Last active
July 22, 2016 22:40
-
-
Save Koze/d9d6655d3a6d09259ba2 to your computer and use it in GitHub Desktop.
Text Speech Example in iOS 8
This file contains 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
// iOS 8 example | |
- (void)speechText:(NSString *)text | |
{ | |
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init]; | |
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text]; | |
utterance.rate = AVSpeechUtteranceMinimumSpeechRate; | |
utterance.volume = 1; | |
// initialize voice with language code | |
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:[AVSpeechSynthesisVoice currentLanguageCode]]; | |
utterance.voice = voice; | |
[synthesizer speakUtterance:utterance]; | |
} |
This file contains 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
// iOS 9 example | |
- (void)speechText:(NSString *)text | |
{ | |
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init]; | |
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text]; | |
utterance.rate = AVSpeechUtteranceMinimumSpeechRate; | |
utterance.volume = 1; | |
// initialize voice with voice identifier | |
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithIdentifier:AVSpeechSynthesisVoiceIdentifierAlex]; | |
utterance.voice = voice; | |
[synthesizer speakUtterance:utterance]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment